From 6ce3556e0b1e39fe5474114137fde0d29ab093af Mon Sep 17 00:00:00 2001 From: Guillaume Nault Date: Wed, 10 Jul 2013 12:54:35 +0200 Subject: memdbg: Allow NULL pointer as argument to free free(NULL) is a no-op, but beside that it's a valid call which should be supported. Signed-off-by: Guillaume Nault --- accel-pppd/memdebug.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/accel-pppd/memdebug.c b/accel-pppd/memdebug.c index 5ca7727..286ddd8 100644 --- a/accel-pppd/memdebug.c +++ b/accel-pppd/memdebug.c @@ -74,20 +74,21 @@ void __export *md_malloc(size_t size, const char *fname, int line) void __export md_free(void *ptr, const char *fname, int line) { - struct mem_t *mem = container_of(ptr, typeof(*mem), data); + struct mem_t *mem; + + if (!ptr) + return; + + mem = container_of(ptr, typeof(*mem), data); - if (!ptr) { - printf("free null pointer at %s:%i\n", fname, line); - abort(); - } - if (mem->magic1 != MAGIC1) { printf("memory corruption:\nfree at %s:%i\n", fname, line); abort(); } if (mem->magic2 != *(uint64_t*)(mem->data + mem->size)) { - printf("memory corruption:\nmalloc(%lu) at %s:%i\nfree at %s:%i\n", (long unsigned)mem->size, mem->fname, mem->line, fname, line); + printf("memory corruption:\nmalloc(%zu) at %s:%i\nfree at %s:%i\n", + mem->size, mem->fname, mem->line, fname, line); abort(); } -- cgit v1.2.3