X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=lib%2Frfxswf.c;h=3ee5c6e656a79a2bd3e8b605f01093cdcd154d79;hb=526824b41844ac59bd38beb20543af5f5dd1a5a0;hp=15b7e2a212b9f6a2cb67eade357dbff8bfc84e6a;hpb=6d22f1376c2fcad7c872db608630468d3abcca23;p=swftools.git diff --git a/lib/rfxswf.c b/lib/rfxswf.c index 15b7e2a..3ee5c6e 100644 --- a/lib/rfxswf.c +++ b/lib/rfxswf.c @@ -50,25 +50,73 @@ // memory allocation -void* rfxalloc(int size) +void* rfx_alloc(int size) { void*ptr; + if(size == 0) { + *(int*)0 = 0xdead; + fprintf(stderr, "Warning: Zero alloc\n"); + return 0; + } + + ptr = malloc(size); + if(!ptr) { + fprintf(stderr, "FATAL: Out of memory\n"); + /* TODO: we should send a signal, so that the debugger kicks in */ + exit(1); + } + return ptr; +} +void* rfx_realloc(void*data, int size) +{ + void*ptr; + if(size == 0) { + *(int*)0 = 0xdead; + fprintf(stderr, "Warning: Zero realloc\n"); + rfx_free(data); + return 0; + } + if(!data) { + ptr = malloc(size); + } else { + ptr = realloc(data, size); + } + + if(!ptr) { + fprintf(stderr, "FATAL: Out of memory\n"); + /* TODO: we should send a signal, so that the debugger kicks in */ + exit(1); + } + return ptr; +} +void* rfx_calloc(int size) +{ + void*ptr; + if(size == 0) { + *(int*)0 = 0xdead; + fprintf(stderr, "Warning: Zero alloc\n"); + return 0; + } #ifdef HAVE_CALLOC ptr = calloc(size); #else ptr = malloc(size); - memset(ptr, 0, size); #endif if(!ptr) { fprintf(stderr, "FATAL: Out of memory\n"); /* TODO: we should send a signal, so that the debugger kicks in */ exit(1); } +#ifndef HAVE_CALLOC + memset(ptr, 0, size); +#endif return ptr; } -void rfxdealloc(void*ptr) +void rfx_free(void*ptr) { + if(!ptr) + return; free(ptr); }