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);
ptr1 = mcalloc(base, CNTXCHUNK);
chunk = newchunk;
}
- chunk->freesize -= size;
- alloc = (MCAllocatedSpace*)( chunk->data + chunk->freesize );
+ alloc = (MCAllocatedSpace*)( chunk->data + chunk->size - chunk->freesize );
alloc->size = size;
alloc->cntx = cntx;
+ chunk->freesize -= size;
if ( cntx->flags & MC_DEBUG ) {
*(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) = MCMAGICKNUMBER;
realsize = alloc->size - MCASHDRSZ;
if ( size > realsize ) {
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize &&
+ MemoryChunk *chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size &&
PTRALIGN(size)-realsize <= alloc->cntx->chunk->freesize ) {
/* 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;
void
mcfree(void * ptr) {
MCAllocatedSpace *alloc = (MCAllocatedSpace*)( (char*)ptr - MCASHDRSZ );
+ MemoryChunk *chunk;
if ( ptr==NULL )
tlog(TL_CRIT|TL_EXIT, "mcfree: free null pointer");
if ( alloc->cntx->flags & MC_DEBUG )
tassert( *(u_int32_t*)((char*)alloc + alloc->size - sizeof(u_int32_t) ) == MCMAGICKNUMBER );
- if ( (char*)alloc == alloc->cntx->chunk->data + alloc->cntx->chunk->freesize ) /* last allocated value */
+ chunk = alloc->cntx->chunk;
+ if ( (char*)alloc == chunk->data + chunk->size - chunk->freesize - alloc->size ) /* last allocated value */
alloc->cntx->chunk->freesize+=alloc->size;
alloc->cntx=NULL;