Extra assertions on free if SLOWDEBUG is enabled: check whether the block exists and has not been freed before

This commit is contained in:
Erik van der Kouwe 2010-05-03 19:42:08 +00:00
parent 4b34ff6903
commit 1137ba9b32

View file

@ -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)