]> AND Public Git Repository - simgrid.git/blobdiff - src/xbt/mmalloc/mmalloc.c
Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : display malloc backtrace according to address
[simgrid.git] / src / xbt / mmalloc / mmalloc.c
index 7584c63335a831f476eb7ed152e5983145aa5374..aaa9e242c94370b1cedb73551a9aeb0e4691a36e 100644 (file)
@@ -125,6 +125,8 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
 
   size_t requested_size = size; // The amount of memory requested by user, for real
 
+  check_fraghead(mdp);
+
   /* Work even if the user was stupid enough to ask a ridicullously small block (even 0-length),
    *    ie return a valid block that can be realloced and freed.
    * glibc malloc does not use this trick but return a constant pointer, but we need to enlist the free fragments later on.
@@ -184,10 +186,10 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
 
       result = mmalloc(mdp, BLOCKSIZE); // does not return NULL
 
-      /* Link all fragments but the first into the free list, and mark their requested size to 0.  */
+      /* Link all fragments but the first into the free list, and mark their requested size to -1.  */
       block = BLOCK(result);
       for (i = 1; i < (size_t) (BLOCKSIZE >> log); ++i) {
-        mdp->heapinfo[block].busy_frag.frag_size[i] = 0;
+        mdp->heapinfo[block].busy_frag.frag_size[i] = -1;
         next = (struct list *) ((char *) result + (i << log));
         next->next = mdp->fraghead[log].next;
         next->prev = &mdp->fraghead[log];
@@ -251,6 +253,9 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
         mdp->heapinfo[block].busy_block.bt_size=xbt_backtrace_no_malloc(mdp->heapinfo[block].busy_block.bt,XBT_BACKTRACE_SIZE);
         mdp -> heapstats.chunks_used++;
         mdp -> heapstats.bytes_used += blocks * BLOCKSIZE;
+
+        check_fraghead(mdp);
+
         return result;
       }
       /* Need large block(s), but found some in the existing heap */
@@ -294,5 +299,6 @@ void *mmalloc_no_memset(xbt_mheap_t mdp, size_t size)
 
   }
   //printf("(%s) Done mallocing. Result is %p\n",xbt_thread_self_name(),result);fflush(stdout);
+  check_fraghead(mdp);
   return (result);
 }