From 16c050ac033cf63b085c65f5c313ed4b71a7108a Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Mon, 6 Feb 2012 11:04:38 +0100 Subject: [PATCH] THROWF won't work in mmalloc: it needs to malloc stuff (I'm sure) --- src/xbt/mmalloc/mfree.c | 11 +++++++---- src/xbt/mmalloc/mm_module.c | 3 ++- src/xbt/mmalloc/mrealloc.c | 11 ++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/xbt/mmalloc/mfree.c b/src/xbt/mmalloc/mfree.c index af92242dc4..5d544122ba 100644 --- a/src/xbt/mmalloc/mfree.c +++ b/src/xbt/mmalloc/mfree.c @@ -30,16 +30,19 @@ void mfree(struct mdesc *mdp, void *ptr) block = BLOCK(ptr); if ((char *) ptr < (char *) mdp->heapbase || block > mdp->heapsize) { - printf("Ouch, this pointer is not mine. I refuse to free it.\n"); - return; + fprintf(stderr,"Ouch, this pointer is not mine. I refuse to free it. I refuse it to death!!\n"); + abort(); } type = mdp->heapinfo[block].type; - if (type<0) - THROWF(arg_error,0,"Asked to free a fragment in a block that is already free. I'm puzzled"); 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(); + break; + case 0: /* Find the free cluster previous to this one in the free list. Start searching at the last block referenced; this may benefit diff --git a/src/xbt/mmalloc/mm_module.c b/src/xbt/mmalloc/mm_module.c index 973c1aeaf1..2ba57960fd 100644 --- a/src/xbt/mmalloc/mm_module.c +++ b/src/xbt/mmalloc/mm_module.c @@ -184,7 +184,8 @@ xbt_mheap_t xbt_mheap_new(int fd, void *baseaddr) if ((mbase = mmorecore(mdp, sizeof(mtemp))) != NULL) { memcpy(mbase, mdp, sizeof(mtemp)); } else { - THROWF(system_error,0,"morecore failed to get some memory!"); + fprintf(stderr, "morecore failed to get some more memory!\n"); + abort(); } /* Add the new heap to the linked list of heaps attached by mmalloc */ diff --git a/src/xbt/mmalloc/mrealloc.c b/src/xbt/mmalloc/mrealloc.c index 0e03a922e2..3176981d68 100644 --- a/src/xbt/mmalloc/mrealloc.c +++ b/src/xbt/mmalloc/mrealloc.c @@ -26,11 +26,9 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) int type; size_t block, blocks, oldlimit; - /* Only keep real realloc and hidden malloc and free to the relevant functions */ + /* Only keep real realloc, and reroute hidden malloc and free to the relevant functions */ if (size == 0) { - fprintf(stderr,"free from realloc..."); mfree(mdp, ptr); - fprintf(stderr,"done\n"); return mmalloc(mdp, 0); } else if (ptr == NULL) { return mmalloc(mdp, size); @@ -49,10 +47,13 @@ void *mrealloc(xbt_mheap_t mdp, void *ptr, size_t size) block = BLOCK(ptr); type = mdp->heapinfo[block].type; - if (type<0) - THROWF(arg_error,0,"Asked realloc a fragment comming from a *free* block. I'm puzzled."); switch (type) { + case -1: + fprintf(stderr, "Asked realloc a fragment comming from a *free* block. I'm puzzled.\n"); + abort(); + break; + case 0: /* Maybe reallocate a large block to a small fragment. */ -- 2.20.1