X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/1d3d1dcdeab30ce6c9e31a12b6195bc4d5ff8a8b..5a935e095de098cfd4f0947e3c30748f09a0721e:/src/xbt/mmalloc/mfree.c diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index 8211efc5ea..754ff3098b 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -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. */ @@ -19,7 +20,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; @@ -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,6 +150,16 @@ 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; + + if( mdp->heapinfo[block].busy_frag.frag_size[frag_nb] == 0){ + UNLOCK(mdp); + THROWF(system_error, 0, "Asked to free a fragment that is already free. I'm puzzled\n"); + } + + 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 @@ -191,8 +202,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;