]> wimlib.net Git - wimlib/commitdiff
util.c: Print error message on out-of-memory
authorEric Biggers <ebiggers3@gmail.com>
Fri, 17 May 2013 05:30:04 +0000 (00:30 -0500)
committerEric Biggers <ebiggers3@gmail.com>
Fri, 17 May 2013 05:30:04 +0000 (00:30 -0500)
src/util.c

index f7ed251c784868028bf12ef2be01cd36221738d8..847510616de12084bfda260de8c13b8bcd835d11 100644 (file)
@@ -414,7 +414,10 @@ static void *(*wimlib_realloc_func)(void *, size_t) = realloc;
 void *
 wimlib_malloc(size_t size)
 {
 void *
 wimlib_malloc(size_t size)
 {
-       return (*wimlib_malloc_func)(size);
+       void *ptr = (*wimlib_malloc_func)(size);
+       if (ptr == NULL && size != 0)
+               ERROR("memory exhausted");
+       return ptr;
 }
 
 void
 }
 
 void
@@ -426,7 +429,10 @@ wimlib_free_memory(void *ptr)
 void *
 wimlib_realloc(void *ptr, size_t size)
 {
 void *
 wimlib_realloc(void *ptr, size_t size)
 {
-       return (*wimlib_realloc_func)(ptr, size);
+       ptr = (*wimlib_realloc_func)(ptr, size);
+       if (ptr == NULL && size != 0)
+               ERROR("memory exhausted");
+       return ptr;
 }
 
 void *
 }
 
 void *