summaryrefslogtreecommitdiff
path: root/lib/memdebug.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2013-12-25 23:30:25 +0100
committerDaniel Stenberg <daniel@haxx.se>2013-12-25 23:30:25 +0100
commit7b057f53fd06ca9f53873992eed5b8c652be0df1 (patch)
tree89e9f1e040f661872cca46a0fd0bd96708410be4 /lib/memdebug.c
parent2dd9bfc5d9fc6aff2da789ee16f7d18089a141e2 (diff)
downloadcurl-7b057f53fd06ca9f53873992eed5b8c652be0df1.tar.gz
curl_dofree: allow free(NULL)
Previously this memdebug free() replacement didn't properly work with a NULL argument which has made us write code that avoids calling free(NULL) - which causes some extra nuisance and unnecessary code. Starting now, we should allow free(NULL) even when built with the memdebug system enabled. free(NULL) is permitted by POSIX
Diffstat (limited to 'lib/memdebug.c')
-rw-r--r--lib/memdebug.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/lib/memdebug.c b/lib/memdebug.c
index 7d68af874..4afa620a0 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -314,7 +314,7 @@ void curl_dofree(void *ptr, int line, const char *source)
{
struct memdebug *mem;
- assert(ptr != NULL);
+ if(ptr) {
#ifdef __INTEL_COMPILER
# pragma warning(push)
@@ -322,17 +322,18 @@ void curl_dofree(void *ptr, int line, const char *source)
/* 1684: conversion from pointer to same-sized integral type */
#endif
- mem = (void *)((char *)ptr - offsetof(struct memdebug, mem));
+ mem = (void *)((char *)ptr - offsetof(struct memdebug, mem));
#ifdef __INTEL_COMPILER
# pragma warning(pop)
#endif
- /* destroy */
- mt_free_fill(mem->mem, mem->size);
+ /* destroy */
+ mt_free_fill(mem->mem, mem->size);
- /* free for real */
- (Curl_cfree)(mem);
+ /* free for real */
+ (Curl_cfree)(mem);
+ }
if(source)
curl_memlog("MEM %s:%d free(%p)\n", source, line, (void *)ptr);