From: Wayne Davison Date: Mon, 3 Aug 2020 21:01:18 +0000 (-0700) Subject: Make my_alloc(NULL) use malloc instead of calloc. X-Git-Tag: v3.2.3~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9375a8c4c2b79a9d44ceae00de7284b77d79033c;p=thirdparty%2Frsync.git Make my_alloc(NULL) use malloc instead of calloc. --- diff --git a/ifuncs.h b/ifuncs.h index b9490588..4037639b 100644 --- a/ifuncs.h +++ b/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) { 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); return buf; } diff --git a/rsync.h b/rsync.h index c688f09c..0f5304ee 100644 --- a/rsync.h +++ b/rsync.h @@ -1324,15 +1324,15 @@ extern int errno; /* handler for null strings in printf format */ #define NS(s) ((s)?(s):"") -extern char *do_malloc; +extern char *do_calloc; /* Convenient wrappers for malloc and realloc. Use them. */ -#define new(type) ((type*)my_alloc(do_malloc, sizeof (type), 1, __FILE__, __LINE__)) -#define new0(type) ((type*)my_alloc(NULL, sizeof (type), 1, __FILE__, __LINE__)) +#define new(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 new_array(type, num) ((type*)my_alloc(do_malloc, (num), sizeof (type), __FILE__, __LINE__)) -#define new_array0(type, num) ((type*)my_alloc(NULL, (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(do_calloc, (num), sizeof (type), __FILE__, __LINE__)) #define realloc_array(ptr, type, num) ((type*)my_alloc((ptr), (num), sizeof (type), __FILE__, __LINE__)) #undef strdup diff --git a/util2.c b/util2.c index 8b61d0b5..a8609a5d 100644 --- a/util2.c +++ b/util2.c @@ -26,7 +26,7 @@ extern size_t max_alloc; -char *do_malloc = "42"; +char *do_calloc = "42"; /** * 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); } if (!ptr) - ptr = calloc(num, size); - else if (ptr == do_malloc) ptr = malloc(num * size); + else if (ptr == do_calloc) + ptr = calloc(num, size); else ptr = realloc(ptr, num * size); if (!ptr && file)