Skip to content

Commit 6e4aec5

Browse files
tfarinatorvalds
authored andcommitted
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 <[email protected]> Signed-off-by: Linus Torvalds <[email protected]>
1 parent bf3c3ac commit 6e4aec5

File tree

3 files changed

+12
-4
lines changed

3 files changed

+12
-4
lines changed

window.c

+2-4
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "edef.h"
1212
#include "efunc.h"
1313
#include "line.h"
14+
#include "wrapper.h"
1415

1516
/*
1617
* Reposition dot in the current window to line "n". If the argument is
@@ -323,10 +324,7 @@ int splitwind(int f, int n)
323324
mlwrite("Cannot split a %d line window", curwp->w_ntrows);
324325
return FALSE;
325326
}
326-
if ((wp = (struct window *)malloc(sizeof(struct window))) == NULL) {
327-
mlwrite("(OUT OF MEMORY)");
328-
return FALSE;
329-
}
327+
wp = xmalloc(sizeof(struct window));
330328
++curbp->b_nwnd; /* Displayed twice. */
331329
wp->w_bufp = curbp;
332330
wp->w_dotp = curwp->w_dotp;

wrapper.c

+8
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,11 @@ int xmkstemp(char *template)
1212
die("Unable to create temporary file");
1313
return fd;
1414
}
15+
16+
void *xmalloc(size_t size)
17+
{
18+
void *ret = malloc(size);
19+
if (!ret)
20+
die("Out of memory");
21+
return ret;
22+
}

wrapper.h

+2
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@
33

44
extern int xmkstemp(char *template);
55

6+
extern void *xmalloc(size_t size);
7+
68
#endif /* WRAPPER_H_ */

0 commit comments

Comments
 (0)