diff options
author | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-07-19 21:54:57 -0300 |
---|---|---|
committer | Rafael G. Martins <rafael@rafaelmartins.eng.br> | 2015-07-19 21:54:57 -0300 |
commit | 3468762d7a830bd68dafdc4c8d489f965fd48b42 (patch) | |
tree | 28b34e92f36275f37280f8816dee266275427b80 /src/utils/mem.c | |
parent | 8aaa346994fe87ce0badfd3ac0c2ee302c86716c (diff) | |
download | blogc-3468762d7a830bd68dafdc4c8d489f965fd48b42.tar.gz blogc-3468762d7a830bd68dafdc4c8d489f965fd48b42.tar.bz2 blogc-3468762d7a830bd68dafdc4c8d489f965fd48b42.zip |
utils/mem: added safe realloc
Diffstat (limited to 'src/utils/mem.c')
-rw-r--r-- | src/utils/mem.c | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/src/utils/mem.c b/src/utils/mem.c index 7befc73..7c5e0a2 100644 --- a/src/utils/mem.c +++ b/src/utils/mem.c @@ -26,3 +26,17 @@ b_malloc(size_t size) } return rv; } + + +void* +b_realloc(void *ptr, size_t size) +{ + // simple things even simpler :P + void *rv = realloc(ptr, size); + if (rv == NULL && size != 0) { + fprintf(stderr, "fatal error: Failed to reallocate memory!\n"); + free(ptr); + exit(1); + } + return rv; +} |