Make my_alloc(NULL) use malloc instead of calloc.
authorWayne Davison <wayne@opencoder.net>
Mon, 3 Aug 2020 21:01:18 +0000 (14:01 -0700)
committerWayne Davison <wayne@opencoder.net>
Mon, 3 Aug 2020 21:01:18 +0000 (14:01 -0700)
ifuncs.h
rsync.h
util2.c

index b94905886fa47d197d20d0183e14e4c8a012eb67..4037639b26a46495fdaaca05039b5c56c461eea8 100644 (file)
--- 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 c688f09cf0bb00e27f6e01b554d59e8348d5ed0c..0f5304ee255493f44c782924f648a702765fe8ce 100644 (file)
--- 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):"<NULL>")
 
-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 8b61d0b51c7c317d09c4e246149a7011f5e5e5eb..a8609a5d5931d60e7907265f94868ef585df785e 100644 (file)
--- 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)