diff options
author | Guillaume Nault <g.nault@alphalink.fr> | 2013-07-10 12:54:35 +0200 |
---|---|---|
committer | Dmitry Kozlov <xeb@mail.ru> | 2013-07-18 22:57:36 +0400 |
commit | 6ce3556e0b1e39fe5474114137fde0d29ab093af (patch) | |
tree | 11b6f0b80135f5858204db2198a618b93f8937a9 | |
parent | 80a7f62ad9c3fabb929e94ebb0745dcb4e42b93a (diff) | |
download | accel-ppp-xebd-6ce3556e0b1e39fe5474114137fde0d29ab093af.tar.gz accel-ppp-xebd-6ce3556e0b1e39fe5474114137fde0d29ab093af.zip |
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 <g.nault@alphalink.fr>
-rw-r--r-- | accel-pppd/memdebug.c | 15 |
1 files 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(); } |