/* DONT include memdebug.h here! */
+struct memdebug {
+ int size;
+ char mem[1];
+};
+
/*
* Note that these debug functions are very simple and they are meant to
* remain so. For advanced analysis, record a log file and write perl scripts
}
-void *curl_domalloc(size_t size, int line, const char *source)
+void *curl_domalloc(size_t wantedsize, int line, const char *source)
{
- void *mem=(malloc)(size);
+ void *mem;
+ size_t size;
+
+ /* alloc at least 64 bytes */
+ size = wantedsize>64?wantedsize:64;
+
+ mem=(malloc)(size);
if(mem)
/* fill memory with junk */
memset(mem, 0xA5, size);
- if(logfile)
+ if(logfile && source)
fprintf(logfile, "MEM %s:%d malloc(%d) = %p\n",
- source, line, size, mem);
+ source, line, wantedsize, mem);
return mem;
}
exit(2);
}
- mem=(strdup)(str);
len=strlen(str)+1;
+
+ mem=curl_domalloc(len, 0, NULL); /* NULL prevents logging */
+ memcpy(mem, str, len);
+
if(logfile)
fprintf(logfile, "MEM %s:%d strdup(%p) (%d) = %p\n",
source, line, str, len, mem);
return mem;
}
-void *curl_dorealloc(void *ptr, size_t size, int line, const char *source)
+void *curl_dorealloc(void *ptr, size_t wantedsize,
+ int line, const char *source)
{
- void *mem=(realloc)(ptr, size);
+ void *mem;
+
+ size_t size = wantedsize>64?wantedsize:64;
+
+ mem=(realloc)(ptr, size);
if(logfile)
fprintf(logfile, "MEM %s:%d realloc(%p, %d) = %p\n",
- source, line, ptr, size, mem);
+ source, line, ptr, wantedsize, mem);
return mem;
}
source, line);
exit(2);
}
+ /* we know this is least 64 bytes, destroy this much */
+ memset(ptr, 0x13, 64);
+ /* free for real */
(free)(ptr);
if(logfile)