]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Delete cbdata-protected data when built --with-valgrind-debug.
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 18 May 2016 22:46:52 +0000 (16:46 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 18 May 2016 22:46:52 +0000 (16:46 -0600)
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.

scripts/find-alive.pl
src/cbdata.cc

index 568b017f62d59282b2dea7df2c01112562067421..21438bc4e98c953253cc87ba3b87738dfb373b90 100755 (executable)
@@ -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+)',
index 8bbaa26beaf2580e832ba78c4291a41f48be5cbc..4f4e32362fc66c798aaa1167a75c136eaf37a025 100644 (file)
@@ -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
 }