]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
My recent ClientBody changes introduced a memory leak. This is awkward
authorwessels <>
Fri, 20 Jan 2006 05:15:18 +0000 (05:15 +0000)
committerwessels <>
Fri, 20 Jan 2006 05:15:18 +0000 (05:15 +0000)
because ConnStateData and ClientBody have references to each other.
ClientBody has a RefCount::Pointer to ConnStateData, which must be NULLed
so the ConnStateData destructor will be called.

src/ClientBody.cc
src/client_side.cc

index e31f54161674ba9ca752b8720e1715e1ca47c31b..6f61da6e13822f9a93794d5ceca0114afaf29b80 100644 (file)
@@ -11,9 +11,12 @@ ClientBody::ClientBody(ConnStateData::Pointer & aConn, HttpRequest *Request) : c
 
 ClientBody::~ClientBody()
 {
-    assert(callback == NULL);
-    assert(buf == NULL);
+    if (cbdata)
+        cbdataReferenceDone(cbdata);
+
     requestUnlink(request);
+
+    conn = NULL;       // refcounted
 }
 
 /* Called by clientReadRequest to process body content */
index 7f6f4a1783c77938f64a006e963c89f15632c2c1..ba1fc6f1042113ffde7347ed2b4648f445003492 100644 (file)
@@ -1,6 +1,6 @@
 
 /*
- * $Id: client_side.cc,v 1.708 2006/01/14 00:06:19 wessels Exp $
+ * $Id: client_side.cc,v 1.709 2006/01/19 22:15:18 wessels Exp $
  *
  * DEBUG: section 33    Client-side Routines
  * AUTHOR: Duane Wessels
@@ -604,6 +604,18 @@ ConnStateData::close()
                     auth_user_request,this);
         auth_user_request->onConnectionClose(this);
     }
+
+    /*
+     * This is awkward: body has a RefCount::Pointer to this.  We must
+     * destroy body so that our own reference count will go to zero.
+     * Furthermore, there currently exists a potential loop because
+     * ~ConnStateData() will delete body if it is not NULL.
+     */
+    if (body) {
+        ClientBody *tmp = body;
+        body = NULL;
+        delete tmp;
+    }
 }
 
 bool