- /* Get the address of the first free fragment in this block. */
- prev = (struct list *)
- ((char *) ADDRESS(block) +
- (mdp->heapinfo[block].busy_frag.first << type));
+ if (type < 0) {
+ fprintf(stderr, "Unkown mmalloc block type.\n");
+ abort();
+ }
+
+ /* Do some of the statistics. */
+ mdp -> heapstats.chunks_used--;
+ mdp -> heapstats.bytes_used -= 1 << type;
+ mdp -> heapstats.chunks_free++;
+ mdp -> heapstats.bytes_free += 1 << type;
+
+ frag_nb = RESIDUAL(ptr, BLOCKSIZE) >> type;
+
+ 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() && 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;