Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Allow dlsym to call free() on memory that is allocated before mmalloc init
[simgrid.git] / src / xbt / mmalloc / mfree.c
index 4863878..652b381 100644 (file)
@@ -29,6 +29,11 @@ void mfree(struct mdesc *mdp, void *ptr)
   size_t block = BLOCK(ptr);
 
   if ((char *) ptr < (char *) mdp->heapbase || block > mdp->heapsize) {
+    if ((char*)ptr <= (char*)mmalloc_preinit_buffer + mmalloc_preinit_buffer_size &&
+        (char*)ptr >= (char*)mmalloc_preinit_buffer)
+      /* This points to the static buffer for fake mallocs done by dlsym before mmalloc initialization, ignore it */
+      return;
+
     fprintf(stderr,"Ouch, this pointer is not mine, I refuse to free it. Give me valid pointers, or give me death!!\n");
     abort();
   }