From: Erik van der Kouwe Date: Mon, 3 May 2010 19:42:08 +0000 (+0000) Subject: Extra assertions on free if SLOWDEBUG is enabled: check whether the block exists... X-Git-Tag: v3.1.7~90 X-Git-Url: http://zhaoyanbai.com/repos/%22/xml/v3/zones/static/named-checkconf.html?a=commitdiff_plain;h=1137ba9b32ee93973065a3dde8c0168d14df24c3;p=minix.git Extra assertions on free if SLOWDEBUG is enabled: check whether the block exists and has not been freed before --- diff --git a/lib/libc/ansi/malloc.c b/lib/libc/ansi/malloc.c index 694fcdc61..2c53dcbaa 100644 --- a/lib/libc/ansi/malloc.c +++ b/lib/libc/ansi/malloc.c @@ -2,7 +2,7 @@ /* replace undef by define */ #define DEBUG /* check assertions */ -#undef SLOWDEBUG /* some extra test loops (requires DEBUG) */ +#define SLOWDEBUG /* some extra test loops (requires DEBUG) */ #ifndef DEBUG #define NDEBUG @@ -179,6 +179,34 @@ free(void *ptr) if (p == 0) return; +#ifdef SLOWDEBUG + { + int found; + char *curr; + + /* block must be in block list */ + assert(_bottom); + found = 0; + for (curr = _bottom; (next = NextSlot(curr)) != 0; curr = next) { + assert(next > curr); + if (curr == p) found = 1; + } + if (curr == p) found = 1; + assert(found); + + /* block must not be in free list */ + if (_empty) { + found = 0; + for (curr = _empty; (next = NextFree(curr)) != 0; curr = next) { + assert(next > curr); + if (curr == p) found = 1; + } + if (curr == p) found = 1; + assert(!found); + } + } +#endif + assert((char *) NextSlot(p) > p); for (prev = 0, next = _empty; next != 0; prev = next, next = NextFree(next)) if (p < next)