]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
using requestLink on adapted->data->header fixes an HttpRequest memory
authorwessels <>
Tue, 10 Jan 2006 03:17:45 +0000 (03:17 +0000)
committerwessels <>
Tue, 10 Jan 2006 03:17:45 +0000 (03:17 +0000)
leak with malformed ICAP/HTTP responses.

src/ICAP/ICAPClientReqmodPrecache.cc
src/ICAP/ICAPModXact.cc

index 00ffcb7ac3c05ed30af59a88d3078f537e67c792..ae91578eca1e06d77139d9a7c0266278c7d0354c 100644 (file)
@@ -182,13 +182,21 @@ void ICAPClientReqmodPrecache::stop(Notify notify)
 void ICAPClientReqmodPrecache::freeVirgin()
 {
     // virgin->data->cause should be NULL;
-    requestUnlink(dynamic_cast<HttpRequest*>(virgin->data->header));
-    virgin->data->header = NULL;
+
+    if (virgin->data->header) {
+        requestUnlink(dynamic_cast<HttpRequest*>(virgin->data->header));
+        virgin->data->header = NULL;
+    }
+
     virgin = NULL;     // refcounted
 }
 
 void ICAPClientReqmodPrecache::freeAdapted()
 {
-    adapted->data->header = NULL;      // we don't own it
+    if (adapted->data->header) {
+        requestUnlink(dynamic_cast<HttpRequest*>(adapted->data->header));
+        adapted->data->header = NULL;
+    }
+
     adapted = NULL;    // refcounted
 }
index b6055b3c805d6a58804207df48cac0759790604c..51189b7b34ff88f36521155f7ea3f2b5e243778f 100644 (file)
@@ -495,10 +495,14 @@ void ICAPModXact::stopSending(bool nicely)
     state.sending = State::sendingDone;
 
     /*
-    * Note on adapted->data->header:  we created the header, but allow the
-    * other side (ICAPClientRespmodPrecache) to take control of it.  We won't touch it here
-    * and instead rely on the Anchor-side to make sure it is properly freed.
-    */
+     * adapted->data->header should be a link_count'ed HttpRequest
+     */
+
+    if (adapted->data->header) {
+        requestUnlink(dynamic_cast<HttpRequest*>(adapted->data->header));
+        adapted->data->header = NULL;
+    }
+
     adapted = NULL; // refcounted
 }
 
@@ -542,7 +546,7 @@ void ICAPModXact::maybeAllocateHttpMsg()
     if (gotEncapsulated("res-hdr")) {
         adapted->data->header = new HttpReply;
     } else if (gotEncapsulated("req-hdr")) {
-        adapted->data->header = new HttpRequest;
+        adapted->data->header = requestLink(new HttpRequest);
     } else
         throw TexcHere("Neither res-hdr nor req-hdr in maybeAllocateHttpMsg()");
 }