Make memory tracking system intolerant with zero sized malloc(),
calloc() and realloc() function calls.
This commit is contained in:
parent
59939313f8
commit
2f6dcaa644
@ -45,6 +45,10 @@
|
|||||||
#include "curl_memory.h"
|
#include "curl_memory.h"
|
||||||
#include "memdebug.h"
|
#include "memdebug.h"
|
||||||
|
|
||||||
|
#ifndef HAVE_ASSERT_H
|
||||||
|
# define assert(x) do { } while (0)
|
||||||
|
#endif
|
||||||
|
|
||||||
struct memdebug {
|
struct memdebug {
|
||||||
size_t size;
|
size_t size;
|
||||||
union {
|
union {
|
||||||
@ -127,6 +131,8 @@ void *curl_domalloc(size_t wantedsize, int line, const char *source)
|
|||||||
struct memdebug *mem;
|
struct memdebug *mem;
|
||||||
size_t size;
|
size_t size;
|
||||||
|
|
||||||
|
assert(wantedsize != 0);
|
||||||
|
|
||||||
if(countcheck("malloc", line, source))
|
if(countcheck("malloc", line, source))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -152,6 +158,9 @@ void *curl_docalloc(size_t wanted_elements, size_t wanted_size,
|
|||||||
struct memdebug *mem;
|
struct memdebug *mem;
|
||||||
size_t size, user_size;
|
size_t size, user_size;
|
||||||
|
|
||||||
|
assert(wanted_elements != 0);
|
||||||
|
assert(wanted_size != 0);
|
||||||
|
|
||||||
if(countcheck("calloc", line, source))
|
if(countcheck("calloc", line, source))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
@ -177,7 +186,7 @@ char *curl_dostrdup(const char *str, int line, const char *source)
|
|||||||
char *mem;
|
char *mem;
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
DEBUGASSERT(str != NULL);
|
assert(str != NULL);
|
||||||
|
|
||||||
if(countcheck("strdup", line, source))
|
if(countcheck("strdup", line, source))
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -202,6 +211,8 @@ void *curl_dorealloc(void *ptr, size_t wantedsize,
|
|||||||
{
|
{
|
||||||
struct memdebug *mem=NULL;
|
struct memdebug *mem=NULL;
|
||||||
|
|
||||||
|
assert(wantedsize != 0);
|
||||||
|
|
||||||
size_t size = sizeof(struct memdebug)+wantedsize;
|
size_t size = sizeof(struct memdebug)+wantedsize;
|
||||||
|
|
||||||
if(countcheck("realloc", line, source))
|
if(countcheck("realloc", line, source))
|
||||||
@ -227,7 +238,7 @@ void curl_dofree(void *ptr, int line, const char *source)
|
|||||||
{
|
{
|
||||||
struct memdebug *mem;
|
struct memdebug *mem;
|
||||||
|
|
||||||
DEBUGASSERT(ptr != NULL);
|
assert(ptr != NULL);
|
||||||
|
|
||||||
mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
|
mem = (struct memdebug *)((char *)ptr - offsetof(struct memdebug, mem));
|
||||||
|
|
||||||
@ -305,7 +316,7 @@ int curl_fclose(FILE *file, int line, const char *source)
|
|||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
DEBUGASSERT(file != NULL);
|
assert(file != NULL);
|
||||||
|
|
||||||
res=fclose(file);
|
res=fclose(file);
|
||||||
if(logfile)
|
if(logfile)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user