]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Prevent memory leaks when cloning Range requests.
authorAlex Rousskov <rousskov@measurement-factory.com>
Tue, 13 Jul 2010 16:43:00 +0000 (10:43 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Tue, 13 Jul 2010 16:43:00 +0000 (10:43 -0600)
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 105135b716ba0eb3c6cc6d2c203ff4b3e7ee6263..123c323910a6f3eeadce29c2998f7ccb1614fe02 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 38633bfd0643bcfbd1789f2ce50a9c45922177ff..d79704ba3d7cf84f0e860879cdd5a0cd4e78421f 100644 (file)
@@ -194,7 +194,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;
@@ -364,6 +364,7 @@ HttpRequest::hdrCacheInit()
 {
     HttpMsg::hdrCacheInit();
 
+    assert(!range);
     range = header.getRange();
 }