summaryrefslogtreecommitdiff
path: root/lib/memdebug.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2000-11-17 15:31:45 +0000
committerDaniel Stenberg <daniel@haxx.se>2000-11-17 15:31:45 +0000
commit3e6a354c4c7e9ff0bccd43221713bbf327d4670f (patch)
treecfaed221eea943df0d14f0bbf7e5ebb8dbdfa0e4 /lib/memdebug.c
parentf0b8aac325ce6ac73b7f488874e9e4d720d09538 (diff)
downloadcurl-3e6a354c4c7e9ff0bccd43221713bbf327d4670f.tar.gz
now exits and alerts on bad uses of strdup() and free()
Diffstat (limited to 'lib/memdebug.c')
-rw-r--r--lib/memdebug.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/lib/memdebug.c b/lib/memdebug.c
index dceb3bea9..9e5ca5040 100644
--- a/lib/memdebug.c
+++ b/lib/memdebug.c
@@ -74,8 +74,17 @@ void *curl_domalloc(size_t size, int line, char *source)
char *curl_dostrdup(char *str, int line, char *source)
{
- char *mem=(strdup)(str);
- size_t len=strlen(str)+1;
+ char *mem;
+ size_t len;
+
+ if(NULL ==str) {
+ fprintf(stderr, "ILLEGAL strdup() on NULL at %s:%d\n",
+ source, line);
+ exit(2);
+ }
+
+ mem=(strdup)(str);
+ len=strlen(str)+1;
fprintf(logfile?logfile:stderr, "MEM %s:%d strdup(%p) (%d) = %p\n",
source, line, str, len, mem);
return mem;
@@ -91,7 +100,14 @@ void *curl_dorealloc(void *ptr, size_t size, int line, char *source)
void curl_dofree(void *ptr, int line, char *source)
{
+ if(NULL == ptr) {
+ fprintf(stderr, "ILLEGAL free() on NULL at %s:%d\n",
+ source, line);
+ exit(2);
+ }
+
(free)(ptr);
+
fprintf(logfile?logfile:stderr, "MEM %s:%d free(%p)\n",
source, line, ptr);
}