From 812666c8e66a21e668c0789d0422aa5a7db54961 Mon Sep 17 00:00:00 2001 From: Christopher Li Date: Tue, 26 Apr 2005 12:00:58 -0700 Subject: [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 Signed-off-by: Linus Torvalds --- write-tree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'write-tree.c') diff --git a/write-tree.c b/write-tree.c index bb7ceedb8..168352853 100644 --- a/write-tree.c +++ b/write-tree.c @@ -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; -- cgit v1.2.1