[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

@ -26,7 +26,7 @@ static int write_tree(struct cache_entry **cachep, int maxentries, const char *b
/* Guess at some random initial size */
size = 8192;
buffer = malloc(size);
buffer = xmalloc(size);
offset = 0;
nr = 0;
@ -68,7 +68,7 @@ static int write_tree(struct cache_entry **cachep, int maxentries, const char *b
entrylen = pathlen - baselen;
if (offset + entrylen + 100 > size) {
size = alloc_nr(offset + entrylen + 100);
buffer = realloc(buffer, size);
buffer = xrealloc(buffer, size);
}
offset += sprintf(buffer + offset, "%o %.*s", mode, entrylen, filename);
buffer[offset++] = 0;