From: wessels <> Date: Fri, 20 Jan 2006 05:15:18 +0000 (+0000) Subject: My recent ClientBody changes introduced a memory leak. This is awkward X-Git-Tag: SQUID_3_0_PRE4~359 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b931b81347af5bfb68eca984f1352c5aeccbe1ae;p=thirdparty%2Fsquid.git My recent ClientBody changes introduced a memory leak. This is awkward 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. --- diff --git a/src/ClientBody.cc b/src/ClientBody.cc index e31f541616..6f61da6e13 100644 --- a/src/ClientBody.cc +++ b/src/ClientBody.cc @@ -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 */ diff --git a/src/client_side.cc b/src/client_side.cc index 7f6f4a1783..ba1fc6f104 100644 --- a/src/client_side.cc +++ b/src/client_side.cc @@ -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