]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Author: Alex Rousskov <rousskov@measurement-factory.com>
authorAmos Jeffries <amosjeffries@squid-cache.org>
Wed, 14 Jul 2010 23:41:16 +0000 (17:41 -0600)
committerAmos Jeffries <amosjeffries@squid-cache.org>
Wed, 14 Jul 2010 23:41:16 +0000 (17:41 -0600)
Prevent memory leaks when cloning Range requests.

HttpRequest::range field was set to a new HttpHdrRange object twice:
once in HttpRequest::clone() and once in HttpRequest::hdrCacheInit()
called from clone().

Polished HttpReply::clone() to make sure HttpReply::hdrCacheInit()
does not use uninitialized HttpReply::sline field and to prevent
benign double-initialization of HttpReply::keep_alive.

src/HttpReply.cc
src/HttpRequest.cc

index 66fe3ed2a43dc64649caf2ddb7d43905f3b67f3e..85ead64e4ca8587f825bda0f1c03cfb7358377fc 100644 (file)
@@ -607,6 +607,7 @@ HttpReply *
 HttpReply::clone() const
 {
     HttpReply *rep = new HttpReply();
+    rep->sline = sline; // used in hdrCacheInit() call below
     rep->header.append(&header);
     rep->hdrCacheInit();
     rep->hdr_sz = hdr_sz;
@@ -615,8 +616,7 @@ HttpReply::clone() const
     rep->body_pipe = body_pipe;
 
     rep->protocol = protocol;
-    rep->sline = sline;
-    rep->keep_alive = keep_alive;
+    // keep_alive is handled in hdrCacheInit()
     return rep;
 }
 
index a74f56a64f34a775488f6c4dec16f75afae26c36..006583d53b8d870efc8b31d7635519987b758611 100644 (file)
@@ -188,7 +188,7 @@ HttpRequest::clone() const
     // urlPath handled in ctor
     copy->canonical = canonical ? xstrdup(canonical) : NULL;
 
-    copy->range = range ? new HttpHdrRange(*range) : NULL;
+    // range handled in hdrCacheInit()
     copy->ims = ims;
     copy->imslen = imslen;
     copy->max_forwards = max_forwards;
@@ -358,6 +358,7 @@ HttpRequest::hdrCacheInit()
 {
     HttpMsg::hdrCacheInit();
 
+    assert(!range);
     range = header.getRange();
 }