[PATCH] introduce xmalloc and xrealloc
Introduce xmalloc and xrealloc to die gracefully with a descriptive message when out of memory, rather than taking a SIGSEGV. Signed-off-by: Christopher Li<chrislgit@chrisli.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
This commit is contained in:
committed by
Linus Torvalds
parent
f2a19340ad
commit
812666c8e6
@ -18,7 +18,7 @@
|
||||
*/
|
||||
static void init_buffer(char **bufp, unsigned int *sizep)
|
||||
{
|
||||
char *buf = malloc(BLOCKING);
|
||||
char *buf = xmalloc(BLOCKING);
|
||||
*sizep = 0;
|
||||
*bufp = buf;
|
||||
}
|
||||
@ -40,7 +40,7 @@ static void add_buffer(char **bufp, unsigned int *sizep, const char *fmt, ...)
|
||||
buf = *bufp;
|
||||
if (newsize > alloc) {
|
||||
alloc = (newsize + 32767) & ~32767;
|
||||
buf = realloc(buf, alloc);
|
||||
buf = xrealloc(buf, alloc);
|
||||
*bufp = buf;
|
||||
}
|
||||
*sizep = newsize;
|
||||
|
||||
Reference in New Issue
Block a user