in clock_getres, check for null pointer before storing result
[musl] / src / malloc / malloc.c
index 239ab9c..9698259 100644 (file)
@@ -20,6 +20,8 @@ static struct {
        volatile int free_lock[2];
 } mal;
 
+int __malloc_replaced;
+
 /* Synchronization tools */
 
 static inline void lock(volatile int *lk)
@@ -121,8 +123,6 @@ void __dump_heap(int x)
 }
 #endif
 
-void *__expand_heap(size_t *);
-
 static struct chunk *expand_heap(size_t n)
 {
        static int heap_lock[2];
@@ -356,10 +356,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);
 }