aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThiago Farina <tfransosi@gmail.com>2010-12-15 23:34:57 -0200
committerLinus Torvalds <torvalds@linux-foundation.org>2010-12-16 08:33:10 -0800
commit6e4aec520ef4f16960fb70d54b9e9a3955d12b03 (patch)
tree7903cc20331726f7aa7a47f920e7e58421c9c961
parentbf3c3ac2bd36ee89c1b18999ac779e86deb7750f (diff)
downloaduemacs-6e4aec520ef4f16960fb70d54b9e9a3955d12b03.tar.gz
uemacs: Add xmalloc as a wrapper function for malloc.
xmalloc checks the returned pointer and dies if it failed to allocate the memory. Use this new function in window.c. More places will be converted to use xmalloc latter. Signed-off-by: Thiago Farina <tfransosi@gmail.com> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--window.c6
-rw-r--r--wrapper.c8
-rw-r--r--wrapper.h2
3 files changed, 12 insertions, 4 deletions
diff --git a/window.c b/window.c
index 6a78b81..86da9a8 100644
--- a/window.c
+++ b/window.c
@@ -11,6 +11,7 @@
#include "edef.h"
#include "efunc.h"
#include "line.h"
+#include "wrapper.h"
/*
* Reposition dot in the current window to line "n". If the argument is
@@ -323,10 +324,7 @@ int splitwind(int f, int n)
mlwrite("Cannot split a %d line window", curwp->w_ntrows);
return FALSE;
}
- if ((wp = (struct window *)malloc(sizeof(struct window))) == NULL) {
- mlwrite("(OUT OF MEMORY)");
- return FALSE;
- }
+ wp = xmalloc(sizeof(struct window));
++curbp->b_nwnd; /* Displayed twice. */
wp->w_bufp = curbp;
wp->w_dotp = curwp->w_dotp;
diff --git a/wrapper.c b/wrapper.c
index 4bf8d7e..a3301e2 100644
--- a/wrapper.c
+++ b/wrapper.c
@@ -12,3 +12,11 @@ int xmkstemp(char *template)
die("Unable to create temporary file");
return fd;
}
+
+void *xmalloc(size_t size)
+{
+ void *ret = malloc(size);
+ if (!ret)
+ die("Out of memory");
+ return ret;
+}
diff --git a/wrapper.h b/wrapper.h
index 0db3b8f..25f5bc0 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -3,4 +3,6 @@
extern int xmkstemp(char *template);
+extern void *xmalloc(size_t size);
+
#endif /* WRAPPER_H_ */