fixes in mcrealloc
authorteodor <teodor>
Tue, 22 Nov 2005 15:33:21 +0000 (15:33 +0000)
committerteodor <teodor>
Tue, 22 Nov 2005 15:33:21 +0000 (15:33 +0000)
memtest.c
tbtree.c
tmalloc.c

index a4536d5..7db7813 100644 (file)
--- 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); 
                printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
 
                ptr = mcrealloc(ptr1, 120); 
-               tassert( ptr==ptr1 );
+               tassert( ptr<ptr1 );
                printf("mixed:%s free:%d\n", ptr, base->chunk->freesize);
        
                printf("mixed:%s free:%d\n", ptr, base->chunk->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);
 
                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);
                printf("mixed:%s free:%d freechild:%d\n", ptr1, base->chunk->freesize, child->chunk->freesize);
 
                freeMemoryContext(child);
index e075b0a..af12db5 100644 (file)
--- 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; 
 
        while(ptr && ptr->pagenumber != pagenumber)
                ptr = ptr->link; 
 
-       return ptr;;
+       return ptr;
 }
 
 static void
 }
 
 static void
index d6c0b76..fee18cb 100644 (file)
--- 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;
                        /* 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;
                        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;