From: teodor Date: Tue, 22 Nov 2005 15:33:21 +0000 (+0000) Subject: fixes in mcrealloc X-Git-Url: http://sigaev.ru/git/gitweb.cgi?a=commitdiff_plain;h=256c8867e1ef5d8e07727231d1e76d91bc719bc2;p=tedtools.git fixes in mcrealloc --- diff --git a/memtest.c b/memtest.c index a4536d5..7db7813 100644 --- a/memtest.c +++ b/memtest.c @@ -118,14 +118,14 @@ main(int argn, char *argv[]) { printf("mixed:%s free:%d\n", ptr, base->chunk->freesize); ptr = mcrealloc(ptr1, 120); - tassert( ptr==ptr1 ); + tassert( ptrchunk->freesize); - ptr = mcalloc(base, CNTXCHUNK); - strcpy(ptr, ptr1); + ptr1 = mcalloc(base, CNTXCHUNK); + strcpy(ptr1, ptr); printf("mixed:%s free:%d freenew:%d\n", ptr1, base->chunk->freesize, base->chunk->next->freesize); - ptr= mcstrdup(child, ptr1); + ptr1= mcstrdup(child, ptr); printf("mixed:%s free:%d freechild:%d\n", ptr1, base->chunk->freesize, child->chunk->freesize); freeMemoryContext(child); diff --git a/tbtree.c b/tbtree.c index e075b0a..af12db5 100644 --- a/tbtree.c +++ b/tbtree.c @@ -208,7 +208,7 @@ findInCache(TBTree *db, u_int32_t pagenumber) { while(ptr && ptr->pagenumber != pagenumber) ptr = ptr->link; - return ptr;; + return ptr; } static void diff --git a/tmalloc.c b/tmalloc.c index d6c0b76..fee18cb 100644 --- a/tmalloc.c +++ b/tmalloc.c @@ -228,6 +228,9 @@ mcrealloc(void * ptr, size_t size) { /* just enlarge */ alloc->cntx->chunk->freesize -= PTRALIGN(size)-realsize; alloc->size+=PTRALIGN(size)-realsize; + memmove( ((char*)alloc) - (PTRALIGN(size)-realsize), alloc, PTRALIGN(size)+MCASHDRSZ ); + alloc = (MCAllocatedSpace*) ( ((char*)alloc) - (PTRALIGN(size)-realsize) ); + ptr = (void*)alloc->data; if ( alloc->cntx->flags & MC_DEBUG ) { memset( (char*)(alloc->data) + realsize, 0xc3, PTRALIGN(size)-realsize ); *(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;