From: Alex Rousskov Date: Wed, 18 May 2016 22:46:52 +0000 (-0600) Subject: Delete cbdata-protected data when built --with-valgrind-debug. X-Git-Tag: SQUID_4_0_11~27 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e57b674b6152a3e0976a1f865ec10b17437316d0;p=thirdparty%2Fsquid.git Delete cbdata-protected data when built --with-valgrind-debug. Valgrind was correctly reporting every cbdata allocation as leaking! AFAICT, these regressions were introduced by a combination of trunk r13977 (Bug 4215: double-free in CBDATA) and trunk r13909 (de-duplicate cbdata deallocate actions). Also fixed and polished cbdata debugging that was printing mismatching Allocating/Freeing pointer values and synced scripts/find-alive.pl. --- diff --git a/scripts/find-alive.pl b/scripts/find-alive.pl index 568b017f62..21438bc4e9 100755 --- a/scripts/find-alive.pl +++ b/scripts/find-alive.pl @@ -55,8 +55,8 @@ my %Pairs = ( 'HttpStateData (\S+) destroyed', ], cbdata => [ - 'cbdataAlloc: (\S+)', - '(?:cbdataFree|cbdataUnlock): Freeing (\S+)', + 'cbdataInternalAlloc: Allocating (\S+)', + 'cbdataRealFree: Freeing (\S+)', ], FD => [ 'fd_open.*\sFD (\d+)', diff --git a/src/cbdata.cc b/src/cbdata.cc index 8bbaa26bea..4f4e32362f 100644 --- a/src/cbdata.cc +++ b/src/cbdata.cc @@ -162,6 +162,13 @@ cbdata::~cbdata() } #endif + +#if WITH_VALGRIND + void *p = data; +#else + void *p = this; +#endif + cbdata_index[type].pool->freeOne(p); } static void @@ -255,25 +262,24 @@ cbdataInternalAlloc(cbdata_type type, const char *file, int line) void cbdataRealFree(cbdata *c, const char *file, const int line) { - void *p = c; +#if WITH_VALGRIND + void *p = c->data; +#else + void *p = (void *)&c->data; +#endif --cbdataCount; - debugs(45, 9, "Freeing " << p); #if USE_CBDATA_DEBUG + debugs(45, 3, "Freeing " << p << ' ' << file << ':' << line); dlinkDelete(&c->link, &cbdataEntries); +#else + debugs(45, 9, "Freeing " << p); #endif #if WITH_VALGRIND - cbdata_htable.erase(c->data); -#if USE_CBDATA_DEBUG - debugs(45, 3, "Call delete " << p << " " << file << ":" << line); -#endif + cbdata_htable.erase(p); delete c; #else -#if USE_CBDATA_DEBUG - debugs(45, 3, "Call cbdata::~cbdata() " << p << " " << file << ":" << line); -#endif - /* This is ugly. But: operator delete doesn't get * the type parameter, so we can't use that * to free the memory. @@ -284,9 +290,7 @@ cbdataRealFree(cbdata *c, const char *file, const int line) * we could use the normal delete operator * and it would Just Work. RBC 20030902 */ - cbdata_type theType = c->type; c->cbdata::~cbdata(); - cbdata_index[theType].pool->freeOne(p); #endif }