diff options
author | Thiago Farina <tfransosi@gmail.com> | 2010-12-15 23:34:57 -0200 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2010-12-16 08:33:10 -0800 |
commit | 6e4aec520ef4f16960fb70d54b9e9a3955d12b03 (patch) | |
tree | 7903cc20331726f7aa7a47f920e7e58421c9c961 | |
parent | bf3c3ac2bd36ee89c1b18999ac779e86deb7750f (diff) | |
download | uemacs-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.c | 6 | ||||
-rw-r--r-- | wrapper.c | 8 | ||||
-rw-r--r-- | wrapper.h | 2 |
3 files changed, 12 insertions, 4 deletions
@@ -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; @@ -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; +} @@ -3,4 +3,6 @@ extern int xmkstemp(char *template); +extern void *xmalloc(size_t size); + #endif /* WRAPPER_H_ */ |