From 6e4aec520ef4f16960fb70d54b9e9a3955d12b03 Mon Sep 17 00:00:00 2001 From: Thiago Farina Date: Wed, 15 Dec 2010 23:34:57 -0200 Subject: [PATCH] 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 Signed-off-by: Linus Torvalds --- window.c | 6 ++---- wrapper.c | 8 ++++++++ wrapper.h | 2 ++ 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_ */