From: Julian Seward Date: Sat, 29 Jul 2006 09:00:25 +0000 (+0000) Subject: Followup to r5991: when leak checking, treat zero-sized blocks as if X-Git-Tag: svn/VALGRIND_3_3_0~715 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1ef8ead90bcc064ddcfa458e2652dcc369b825af;p=thirdparty%2Fvalgrind.git Followup to r5991: when leak checking, treat zero-sized blocks as if they had size one. Otherwise they appear to cover no address space, so no pointers to them are ever found, and so they are always incorrectly marked as leaked. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5994 --- diff --git a/memcheck/mc_leakcheck.c b/memcheck/mc_leakcheck.c index 921ee919de..f194500720 100644 --- a/memcheck/mc_leakcheck.c +++ b/memcheck/mc_leakcheck.c @@ -201,6 +201,14 @@ Int find_shadow_for ( Addr ptr, mid = (lo + hi) / 2; a_mid_lo = shadows[mid]->data; a_mid_hi = shadows[mid]->data + shadows[mid]->size; + /* Extent of block 'mid' is [a_mid_lo .. a_mid_hi). + Special-case zero-sized blocks - treat them as if they had + size 1. Not doing so causes them to not cover any address + range at all and so will never be identified as the target of + any pointer, which causes them to be incorrectly reported as + definitely leaked. */ + if (shadows[mid]->size == 0) + a_mid_hi++; if (ptr < a_mid_lo) { hi = mid-1; @@ -346,7 +354,9 @@ static void lc_markstack_push_WRK(Addr ptr, Int clique) tl_assert(sh_no >= 0 && sh_no < lc_n_shadows); tl_assert(ptr >= lc_shadows[sh_no]->data); - tl_assert(ptr < lc_shadows[sh_no]->data + lc_shadows[sh_no]->size); + tl_assert(ptr < lc_shadows[sh_no]->data + + lc_shadows[sh_no]->size + + (lc_shadows[sh_no]->size==0 ? 1 : 0)); if (lc_markstack[sh_no].state == Unreached) { if (0)