Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Return immediately if p==NULL.
authorArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 11 Oct 2012 14:10:14 +0000 (16:10 +0200)
committerArnaud Giersch <arnaud.giersch@iut-bm.univ-fcomte.fr>
Thu, 11 Oct 2012 15:33:29 +0000 (17:33 +0200)
Prevents valgrind from beeing hung at exit on a free(0).

src/xbt/mmalloc/mm_legacy.c

index f7d0f71..96610ee 100644 (file)
@@ -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