[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:
Christopher Li
2005-04-26 12:00:58 -07:00
committed by Linus Torvalds
parent f2a19340ad
commit 812666c8e6
18 changed files with 54 additions and 41 deletions

View File

@ -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;