about summary refs log tree commit diff
path: root/src/malloc/calloc.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/malloc/calloc.c')
-rw-r--r--src/malloc/calloc.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/malloc/calloc.c b/src/malloc/calloc.c
index 322193ca..bf6bddca 100644
--- a/src/malloc/calloc.c
+++ b/src/malloc/calloc.c
@@ -2,6 +2,7 @@
 #include <stdint.h>
 #include <string.h>
 #include <errno.h>
+#include "dynlink.h"
 
 static size_t mal0_clear(char *p, size_t n)
 {
@@ -23,6 +24,12 @@ static size_t mal0_clear(char *p, size_t n)
 	}
 }
 
+static int allzerop(void *p)
+{
+	return 0;
+}
+weak_alias(allzerop, __malloc_allzerop);
+
 void *calloc(size_t m, size_t n)
 {
 	if (n && m > (size_t)-1/n) {
@@ -31,7 +38,8 @@ void *calloc(size_t m, size_t n)
 	}
 	n *= m;
 	void *p = malloc(n);
-	if (!p) return p;
+	if (!p || (!__malloc_replaced && __malloc_allzerop(p)))
+		return p;
 	n = mal0_clear(p, n);
 	return memset(p, 0, n);
 }