]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed probable memory accounting leak. We were calling free() when
authorwessels <>
Tue, 31 Mar 1998 05:58:51 +0000 (05:58 +0000)
committerwessels <>
Tue, 31 Mar 1998 05:58:51 +0000 (05:58 +0000)
we should have been calling memFree() in cbdataUnlock()

src/cbdata.cc

index 4ad95a5a836579a9381a53f7ad7dc7009db63f55..f3083f7b3fca24f38125eea02410d20b5f33f4db 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: cbdata.cc,v 1.17 1998/03/27 18:46:47 wessels Exp $
+ * $Id: cbdata.cc,v 1.18 1998/03/30 22:58:51 wessels Exp $
  *
  * DEBUG: section 45    Callback Data Registry
  * AUTHOR: Duane Wessels
@@ -80,6 +80,7 @@ typedef struct _cbdata {
 
 static HASHCMP cbdata_cmp;
 static HASHHASH cbdata_hash;
+static void cbdataReallyFree(cbdata *c);
 
 static int
 cbdata_cmp(const void *p1, const void *p2)
@@ -128,11 +129,25 @@ cbdataAdd(const void *p, mem_type mem_type)
     cbdataCount++;
 }
 
+static void
+cbdataReallyFree(cbdata *c)
+{
+    mem_type mem_type = c->mem_type;
+    void *p = (void *) c->key;
+    hash_remove_link(htable, (hash_link *) c);
+    cbdataCount--;
+    xfree(c);
+    debug(45, 3) ("cbdataReallyFree: Freeing %p\n", p);
+    if (mem_type == MEM_NONE)
+        xfree(p);
+    else
+        memFree(mem_type, p);
+}
+
 void
 cbdataFree(void *p)
 {
     cbdata *c = (cbdata *) hash_lookup(htable, p);
-    mem_type mem_type;
     assert(p);
     debug(45, 3) ("cbdataFree: %p\n", p);
     assert(c != NULL);
@@ -142,15 +157,7 @@ cbdataFree(void *p)
            p, c->locks);
        return;
     }
-    hash_remove_link(htable, (hash_link *) c);
-    cbdataCount--;
-    mem_type = c->mem_type;
-    xfree(c);
-    debug(45, 3) ("cbdataFree: freeing %p\n", p);
-    if (mem_type == MEM_NONE)
-       xfree(p);
-    else
-       memFree(mem_type, p);
+    cbdataReallyFree(c);
 }
 
 void
@@ -178,11 +185,7 @@ cbdataUnlock(const void *p)
     c->locks--;
     if (c->valid || c->locks)
        return;
-    hash_remove_link(htable, (hash_link *) c);
-    cbdataCount--;
-    xfree(c);
-    debug(45, 3) ("cbdataUnlock: Freeing %p\n", p);
-    xfree((void *) p);
+    cbdataReallyFree(c);
 }
 
 int