about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/internal/malloc_impl.h3
-rw-r--r--src/malloc/malloc.c13
-rw-r--r--src/malloc/memalign.c2
3 files changed, 13 insertions, 5 deletions
diff --git a/src/internal/malloc_impl.h b/src/internal/malloc_impl.h
index 4c4a4b46..5d025b06 100644
--- a/src/internal/malloc_impl.h
+++ b/src/internal/malloc_impl.h
@@ -39,4 +39,7 @@ struct bin {
 __attribute__((__visibility__("hidden")))
 void __bin_chunk(struct chunk *);
 
+__attribute__((__visibility__("hidden")))
+extern int __malloc_replaced;
+
 #endif
diff --git a/src/malloc/malloc.c b/src/malloc/malloc.c
index 239ab9c6..d72883e1 100644
--- a/src/malloc/malloc.c
+++ b/src/malloc/malloc.c
@@ -20,6 +20,8 @@ static struct {
 	volatile int free_lock[2];
 } mal;
 
+int __malloc_replaced;
+
 /* Synchronization tools */
 
 static inline void lock(volatile int *lk)
@@ -356,10 +358,13 @@ void *calloc(size_t m, size_t n)
 	}
 	n *= m;
 	void *p = malloc(n);
-	if (!p || IS_MMAPPED(MEM_TO_CHUNK(p)))
-		return p;
-	if (n >= PAGE_SIZE)
-		n = mal0_clear(p, PAGE_SIZE, n);
+	if (!p) return p;
+	if (!__malloc_replaced) {
+		if (IS_MMAPPED(MEM_TO_CHUNK(p)))
+			return p;
+		if (n >= PAGE_SIZE)
+			n = mal0_clear(p, PAGE_SIZE, n);
+	}
 	return memset(p, 0, n);
 }
 
diff --git a/src/malloc/memalign.c b/src/malloc/memalign.c
index 7246a99b..8a6152f4 100644
--- a/src/malloc/memalign.c
+++ b/src/malloc/memalign.c
@@ -13,7 +13,7 @@ void *__memalign(size_t align, size_t len)
 		return 0;
 	}
 
-	if (len > SIZE_MAX - align) {
+	if (len > SIZE_MAX - align || __malloc_replaced) {
 		errno = ENOMEM;
 		return 0;
 	}