]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: de-duplicate cbdata deallocate actions
authorAmos Jeffries <squid3@treenet.co.nz>
Thu, 5 Feb 2015 11:34:16 +0000 (03:34 -0800)
committerAmos Jeffries <squid3@treenet.co.nz>
Thu, 5 Feb 2015 11:34:16 +0000 (03:34 -0800)
src/cbdata.cc

index 8c149ec790c4e5014ff0bd9b26f388c3ae394ddf..829fb98936aaebd174d0d55c40dcc00d746c7b4d 100644 (file)
@@ -276,38 +276,14 @@ cbdataInternalAlloc(cbdata_type type, const char *file, int line)
     return p;
 }
 
-void *
-cbdataInternalFree(void *p, const char *file, int line)
+void
+cbdataRealFree(cbdata *c, const char *file, const int line)
 {
-    cbdata *c;
-#if HASHED_CBDATA
-    c = (cbdata *) hash_lookup(cbdata_htable, p);
-#else
-    c = (cbdata *) (((char *) p) - cbdata::Offset);
-#endif
-#if USE_CBDATA_DEBUG
-    debugs(45, 3, p << " " << file << ":" << line);
-#else
-    debugs(45, 9, p);
-#endif
-
-    c->check(__LINE__);
-    assert(c->valid);
-    c->valid = 0;
-#if USE_CBDATA_DEBUG
-
-    c->addHistory("Free", file, line);
-#endif
-
-    if (c->locks) {
-        debugs(45, 9, p << " has " << c->locks << " locks, not freeing");
-        return NULL;
-    }
+    void *p = c;
 
     --cbdataCount;
     debugs(45, 9, "Freeing " << p);
 #if USE_CBDATA_DEBUG
-
     dlinkDelete(&c->link, &cbdataEntries);
 #endif
 
@@ -325,17 +301,47 @@ cbdataInternalFree(void *p, const char *file, int line)
 #if HASHED_CBDATA
     hash_remove_link(cbdata_htable, &c->hash);
 #if USE_CBDATA_DEBUG
-    debugs(45, 3, "Call delete " << (void*)c << " " << file << ":" << line);
+    debugs(45, 3, "Call delete " << p << " " << file << ":" << line);
 #endif
     delete c;
-    cbdata_index[theType].pool->freeOne((void *)p);
 #else
 #if USE_CBDATA_DEBUG
-    debugs(45, 3, "Call cbdata::~cbdata() " << (void*)c << " " << file << ":" << line);
+    debugs(45, 3, "Call cbdata::~cbdata() " << p << " " << file << ":" << line);
 #endif
     c->cbdata::~cbdata();
-    cbdata_index[theType].pool->freeOne(c);
 #endif
+    cbdata_index[theType].pool->freeOne(p);
+}
+
+void *
+cbdataInternalFree(void *p, const char *file, int line)
+{
+    cbdata *c;
+#if HASHED_CBDATA
+    c = (cbdata *) hash_lookup(cbdata_htable, p);
+#else
+    c = (cbdata *) (((char *) p) - cbdata::Offset);
+#endif
+#if USE_CBDATA_DEBUG
+    debugs(45, 3, p << " " << file << ":" << line);
+#else
+    debugs(45, 9, p);
+#endif
+
+    c->check(__LINE__);
+    assert(c->valid);
+    c->valid = 0;
+#if USE_CBDATA_DEBUG
+
+    c->addHistory("Free", file, line);
+#endif
+
+    if (c->locks) {
+        debugs(45, 9, p << " has " << c->locks << " locks, not freeing");
+        return NULL;
+    }
+
+    cbdataRealFree(c, file, line);
     return NULL;
 }
 
@@ -414,41 +420,7 @@ cbdataInternalUnlock(const void *p)
         return;
     }
 
-    --cbdataCount;
-
-    debugs(45, 9, "Freeing " << p);
-
-#if USE_CBDATA_DEBUG
-
-    dlinkDelete(&c->link, &cbdataEntries);
-
-#endif
-
-    /* This is ugly. But: operator delete doesn't get
-     * the type parameter, so we can't use that
-     * to free the memory.
-     * So, we free it ourselves.
-     * Note that this means a non-placement
-     * new would be a seriously bad idea.
-     * Lastly, if we where a templated class,
-     * we could use the normal delete operator
-     * and it would Just Work. RBC 20030902
-     */
-    cbdata_type theType = c->type;
-#if HASHED_CBDATA
-    hash_remove_link(cbdata_htable, &c->hash);
-#if USE_CBDATA_DEBUG
-    debugs(45, 3, "Call delete " << (void*)c << " " << file << ":" << line);
-#endif
-    delete c;
-    cbdata_index[theType].pool->freeOne((void *)p);
-#else
-#if USE_CBDATA_DEBUG
-    debugs(45, 3, "Call cbdata::~cbdata() " << (void*)c << " " << file << ":" << line);
-#endif
-    c->cbdata::~cbdata();
-    cbdata_index[theType].pool->freeOne(c);
-#endif
+    cbdataRealFree(c, file, line);
 }
 
 int