Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
set size to -1 for free fragments in new fragmented block
[simgrid.git] / src / xbt / mmalloc / mfree.c
index 64e0982..e8242f6 100644 (file)
@@ -11,6 +11,7 @@
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 #include "mmprivate.h"
+#include "xbt/ex.h"
 
 /* Return memory to the heap.
    Like `mfree' but don't call a mfree_hook if there is one.  */
@@ -39,8 +40,8 @@ void mfree(struct mdesc *mdp, void *ptr)
 
   switch (type) {
   case -1: /* Already free */
-    fprintf(stderr,"Asked to free a fragment in a block that is already free. I'm puzzled\n");
-    abort();
+    UNLOCK(mdp);
+    THROWF(system_error, 0, "Asked to free a fragment in a block that is already free. I'm puzzled\n");
     break;
     
   case 0:
@@ -149,9 +150,15 @@ void mfree(struct mdesc *mdp, void *ptr)
       ((char *) ADDRESS(block) +
        (mdp->heapinfo[block].busy_frag.first << type));
 
-    /* Set size used in the fragment to 0 */
     frag_nb = RESIDUAL(ptr, BLOCKSIZE) >> type;
-    mdp->heapinfo[block].busy_frag.frag_size[frag_nb] = 0;
+
+    if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == -1){
+      UNLOCK(mdp);
+      THROWF(system_error, 0, "Asked to free a fragment that is already free. I'm puzzled\n");
+    }
+
+    /* Set size used in the fragment to -1 */
+    mdp->heapinfo[block].busy_frag.frag_size[frag_nb] = -1;
 
     if (mdp->heapinfo[block].busy_frag.nfree ==
         (BLOCKSIZE >> type) - 1) {