changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: pool: avoid triggering assert(b->magic != FREE_MAGIC) in blocksetsize() for mallocalignl()

changeset 4412: de32ddc1b04b
parent 4411: b79b383c8ae0
child 4413: 7ec63d7bcad7
author: cinap_lenrek@felloff.net
date: Wed, 08 Apr 2015 21:04:10 +0200
files: sys/src/libc/port/pool.c
description: pool: avoid triggering assert(b->magic != FREE_MAGIC) in blocksetsize() for mallocalignl()

when we trim the front of a block with freefromfront(),
the block magic of the back was not initialized which
could sometimes trigger the assert in blocksetsize()
to fail. fix is to just move the initialization of the
magic field before the blocksetsize() call.

the second b->magic = UNALLOC_MAGIC isnt really required
but just done for consistency with the trim() code above.
     1.1--- a/sys/src/libc/port/pool.c
     1.2+++ b/sys/src/libc/port/pool.c
     1.3@@ -520,10 +520,10 @@ freefromfront(Pool *p, Alloc *b, ulong s
     1.4 	skip = skip&~(p->quantum-1);
     1.5 	if(skip >= 0x1000 || (skip >= b->size>>2 && skip >= MINBLOCKSIZE && skip >= p->minblock)){
     1.6 		bb = (Alloc*)((uchar*)b+skip);
     1.7+		bb->magic = UNALLOC_MAGIC;
     1.8 		blocksetsize(bb, b->size-skip);
     1.9-		bb->magic = UNALLOC_MAGIC;
    1.10+		b->magic = UNALLOC_MAGIC;
    1.11 		blocksetsize(b, skip);
    1.12-		b->magic = UNALLOC_MAGIC;
    1.13 		pooladd(p, b);
    1.14 		return bb;
    1.15 	}