Make my_alloc(NULL) use malloc instead of calloc.
This commit is contained in:
2
ifuncs.h
2
ifuncs.h
@@ -105,7 +105,7 @@ free_stat_x(stat_x *sx_p)
|
|||||||
static inline char *my_strdup(const char *str, const char *file, int line)
|
static inline char *my_strdup(const char *str, const char *file, int line)
|
||||||
{
|
{
|
||||||
int len = strlen(str)+1;
|
int len = strlen(str)+1;
|
||||||
char *buf = my_alloc(do_malloc, len, 1, file, line);
|
char *buf = my_alloc(NULL, len, 1, file, line);
|
||||||
memcpy(buf, str, len);
|
memcpy(buf, str, len);
|
||||||
return buf;
|
return buf;
|
||||||
}
|
}
|
||||||
|
|||||||
10
rsync.h
10
rsync.h
@@ -1324,15 +1324,15 @@ extern int errno;
|
|||||||
/* handler for null strings in printf format */
|
/* handler for null strings in printf format */
|
||||||
#define NS(s) ((s)?(s):"<NULL>")
|
#define NS(s) ((s)?(s):"<NULL>")
|
||||||
|
|
||||||
extern char *do_malloc;
|
extern char *do_calloc;
|
||||||
|
|
||||||
/* Convenient wrappers for malloc and realloc. Use them. */
|
/* Convenient wrappers for malloc and realloc. Use them. */
|
||||||
#define new(type) ((type*)my_alloc(do_malloc, sizeof (type), 1, __FILE__, __LINE__))
|
#define new(type) ((type*)my_alloc(NULL, sizeof (type), 1, __FILE__, __LINE__))
|
||||||
#define new0(type) ((type*)my_alloc(NULL, sizeof (type), 1, __FILE__, __LINE__))
|
#define new0(type) ((type*)my_alloc(do_calloc, sizeof (type), 1, __FILE__, __LINE__))
|
||||||
#define realloc_buf(ptr, num) my_alloc((ptr), (num), 1, __FILE__, __LINE__)
|
#define realloc_buf(ptr, num) my_alloc((ptr), (num), 1, __FILE__, __LINE__)
|
||||||
|
|
||||||
#define new_array(type, num) ((type*)my_alloc(do_malloc, (num), sizeof (type), __FILE__, __LINE__))
|
#define new_array(type, num) ((type*)my_alloc(NULL, (num), sizeof (type), __FILE__, __LINE__))
|
||||||
#define new_array0(type, num) ((type*)my_alloc(NULL, (num), sizeof (type), __FILE__, __LINE__))
|
#define new_array0(type, num) ((type*)my_alloc(do_calloc, (num), sizeof (type), __FILE__, __LINE__))
|
||||||
#define realloc_array(ptr, type, num) ((type*)my_alloc((ptr), (num), sizeof (type), __FILE__, __LINE__))
|
#define realloc_array(ptr, type, num) ((type*)my_alloc((ptr), (num), sizeof (type), __FILE__, __LINE__))
|
||||||
|
|
||||||
#undef strdup
|
#undef strdup
|
||||||
|
|||||||
6
util2.c
6
util2.c
@@ -26,7 +26,7 @@
|
|||||||
|
|
||||||
extern size_t max_alloc;
|
extern size_t max_alloc;
|
||||||
|
|
||||||
char *do_malloc = "42";
|
char *do_calloc = "42";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sleep for a specified number of milliseconds.
|
* Sleep for a specified number of milliseconds.
|
||||||
@@ -80,9 +80,9 @@ void *my_alloc(void *ptr, size_t num, size_t size, const char *file, int line)
|
|||||||
exit_cleanup(RERR_MALLOC);
|
exit_cleanup(RERR_MALLOC);
|
||||||
}
|
}
|
||||||
if (!ptr)
|
if (!ptr)
|
||||||
ptr = calloc(num, size);
|
|
||||||
else if (ptr == do_malloc)
|
|
||||||
ptr = malloc(num * size);
|
ptr = malloc(num * size);
|
||||||
|
else if (ptr == do_calloc)
|
||||||
|
ptr = calloc(num, size);
|
||||||
else
|
else
|
||||||
ptr = realloc(ptr, num * size);
|
ptr = realloc(ptr, num * size);
|
||||||
if (!ptr && file)
|
if (!ptr && file)
|
||||||
|
|||||||
Reference in New Issue
Block a user