]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Summary: BUGFIX: httpStateData leaks.
authorrobertc <>
Thu, 10 Jul 2003 15:37:56 +0000 (15:37 +0000)
committerrobertc <>
Thu, 10 Jul 2003 15:37:56 +0000 (15:37 +0000)
Keywords:

CommRead's operator= was leaking cbdatareferences when assigning to an already extant object.
Fixed. We could benefit by generalising the algorithm for refcounting classes further - to allow the reuse of RefCount's logic with classes owning CBDATA - like CommRead.

src/CommRead.h

index bf0d632242f221f6fc8d8e7a0255dfa880efc473..5c93a377f8105f3fe24378b11903f23009b8f66f 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: CommRead.h,v 1.4 2003/07/06 13:43:40 hno Exp $
+ * $Id: CommRead.h,v 1.5 2003/07/10 09:37:56 robertc Exp $
  *
  * DEBUG: section 5    Comms
  * AUTHOR: Robert Collins <robertc@squid-cache.org>
@@ -67,24 +67,20 @@ public:
 
     ~CallBack()
     {
-        if (data)
-            cbdataReferenceDone(data);
+        replaceData (NULL);
     }
 
     CallBack &operator = (CallBack const & rhs)
     {
         handler = rhs.handler;
 
-        if (rhs.data)
-            data = cbdataReference (rhs.data);
-        else
-            data = NULL;
+        replaceData (rhs.data);
 
         return *this;
     }
 
 
-bool operator == (CallBack const &rhs) { return handler==rhs.handler && data==rhs.data;}
+    bool operator == (CallBack const &rhs) { return handler==rhs.handler && data==rhs.data;}
 
 #if 0
     // twould be nice - RBC 20030307
@@ -93,6 +89,20 @@ bool operator == (CallBack const &rhs) { return handler==rhs.handler && data==rh
 
     C *handler;
     void *data;
+
+private:
+    void replaceData(void *someData)
+    {
+        void *temp = NULL;
+
+        if (someData)
+            temp = cbdataReference(someData);
+
+        if (data)
+            cbdataReferenceDone(data);
+
+        data = temp;
+    }
 };
 
 #if 0