diff options
author | Christopher Li <git@chrisli.org> | 2005-04-26 12:00:58 -0700 |
---|---|---|
committer | Linus Torvalds <torvalds@ppc970.osdl.org> | 2005-04-26 12:00:58 -0700 |
commit | 812666c8e66a21e668c0789d0422aa5a7db54961 (patch) | |
tree | b98a096f4b3c70aac3110f905a1367c23b402cca /cache.h | |
parent | f2a19340ada1188e278d5b198d3466ed7411e2d4 (diff) | |
download | git-812666c8e66a21e668c0789d0422aa5a7db54961.tar.gz |
[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.h | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -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 */ |