Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : set size used to 0 when free fragment
[simgrid.git] / src / xbt / mmalloc / mfree.c
index fae6ed0..64e0982 100644 (file)
@@ -19,7 +19,7 @@
 void mfree(struct mdesc *mdp, void *ptr)
 {
   int type;
-  size_t block;
+  size_t block, frag_nb;
   register size_t i;
   struct list *prev, *next;
   int it;
@@ -51,8 +51,6 @@ void mfree(struct mdesc *mdp, void *ptr)
     mdp -> heapstats.bytes_free +=
       mdp -> heapinfo[block].busy_block.size * BLOCKSIZE;
 
-    memset(ptr, 0, mdp -> heapinfo[block].busy_block.size * BLOCKSIZE);
-    
     /* Find the free cluster previous to this one in the free list.
        Start searching at the last block referenced; this may benefit
        programs with locality of allocation.  */
@@ -146,14 +144,15 @@ void mfree(struct mdesc *mdp, void *ptr)
     mdp -> heapstats.chunks_free++;
     mdp -> heapstats.bytes_free += 1 << type;
 
-    memset(ptr, 0, 1 << type);
-
-    
     /* Get the address of the first free fragment in this block.  */
     prev = (struct list *)
       ((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.nfree ==
         (BLOCKSIZE >> type) - 1) {
       /* If all fragments of this block are free, remove them
@@ -196,8 +195,7 @@ void mfree(struct mdesc *mdp, void *ptr)
        it is the first free fragment of this block. */
       prev = (struct list *) ptr;
       mdp->heapinfo[block].busy_frag.nfree = 1;
-      mdp->heapinfo[block].busy_frag.first =
-        RESIDUAL(ptr, BLOCKSIZE) >> type;
+      mdp->heapinfo[block].busy_frag.first = frag_nb;
       prev->next = mdp->fraghead[type].next;
       prev->prev = &mdp->fraghead[type];
       prev->prev->next = prev;