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_ */