+ 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");
+ }
+
+ if(MC_is_active()){
+ if(mdp->heapinfo[block].busy_frag.ignore[frag_nb] > 0)
+ MC_remove_ignore_heap(ptr, mdp->heapinfo[block].busy_frag.frag_size[frag_nb]);
+ }
+
+ /* Set size used in the fragment to -1 */
+ mdp->heapinfo[block].busy_frag.frag_size[frag_nb] = -1;
+ mdp->heapinfo[block].busy_frag.ignore[frag_nb] = 0;
+
+// fprintf(stderr,"nfree:%zu capa:%d\n", mdp->heapinfo[block].busy_frag.nfree,(BLOCKSIZE >> type));
+ if (mdp->heapinfo[block].busy_frag.nfree ==
+ (BLOCKSIZE >> type) - 1) {
+ /* If all fragments of this block are free, remove this block from its swag and free the whole block. */
+ xbt_swag_remove(&mdp->heapinfo[block],&mdp->fraghead[type]);
+
+ /* pretend that this block is used and free it so that it gets properly coalesced with adjacent free blocks */
+ mdp->heapinfo[block].type = 0;
+ mdp->heapinfo[block].busy_block.size = 1;
+ mdp->heapinfo[block].busy_block.busy_size = 0;
+
+ /* Keep the statistics accurate. */
+ mdp -> heapstats.chunks_used++;
+ mdp -> heapstats.bytes_used += BLOCKSIZE;
+ mdp -> heapstats.chunks_free -= BLOCKSIZE >> type;
+ mdp -> heapstats.bytes_free -= BLOCKSIZE;
+