From de05fff4ce289c10aea0f0c80476809e4091a247 Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Thu, 11 Oct 2012 16:10:14 +0200 Subject: [PATCH] Return immediately if p==NULL. Prevents valgrind from beeing hung at exit on a free(0). --- src/xbt/mmalloc/mm_legacy.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/xbt/mmalloc/mm_legacy.c b/src/xbt/mmalloc/mm_legacy.c index f7d0f71fd2..96610ee1ca 100644 --- a/src/xbt/mmalloc/mm_legacy.c +++ b/src/xbt/mmalloc/mm_legacy.c @@ -69,11 +69,13 @@ void *realloc(void *p, size_t s) void free(void *p) { - xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); + if (p != NULL) { + xbt_mheap_t mdp = __mmalloc_current_heap ?: (xbt_mheap_t) mmalloc_preinit(); - LOCK(mdp); - mfree(mdp, p); - UNLOCK(mdp); + LOCK(mdp); + mfree(mdp, p); + UNLOCK(mdp); + } } #endif -- 2.20.1