aboutsummaryrefslogtreecommitdiff
path: root/cache.h
diff options
context:
space:
mode:
authorChristopher Li <git@chrisli.org>2005-04-26 12:00:58 -0700
committerLinus Torvalds <torvalds@ppc970.osdl.org>2005-04-26 12:00:58 -0700
commit812666c8e66a21e668c0789d0422aa5a7db54961 (patch)
treeb98a096f4b3c70aac3110f905a1367c23b402cca /cache.h
parentf2a19340ada1188e278d5b198d3466ed7411e2d4 (diff)
downloadgit-812666c8e66a21e668c0789d0422aa5a7db54961.tar.gz
git-812666c8e66a21e668c0789d0422aa5a7db54961.tar.xz
[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>
Diffstat (limited to 'cache.h')
-rw-r--r--cache.h16
1 files changed, 16 insertions, 0 deletions
diff --git a/cache.h b/cache.h
index 4ef80c392..3277d4870 100644
--- a/cache.h
+++ b/cache.h
@@ -147,4 +147,20 @@ extern void *read_tree_with_tree_or_commit_sha1(const unsigned char *sha1,
unsigned long *size,
unsigned char *tree_sha1_ret);
+static inline void *xmalloc(int size)
+{
+ void *ret = malloc(size);
+ if (!ret)
+ die("Out of memory, malloc failed");
+ return ret;
+}
+
+static inline void *xrealloc(void *ptr, int size)
+{
+ void *ret = realloc(ptr, size);
+ if (!ret)
+ die("Out of memory, realloc failed");
+ return ret;
+}
+
#endif /* CACHE_H */