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.
Alex.
=== modified file 'src/HttpReply.cc'
--- src/HttpReply.cc 2009-11-18 08:54:02 +
+++ src/HttpReply.cc 2010-01-26 21:05:30 +
@@ -606,6 +606,7 @@
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;
@@ -614,8 +615,7 @@
rep->body_pipe = body_pipe;
rep->protocol = protocol;
-rep->sline = sline;
-rep->keep_alive = keep_alive;
+// keep_alive is handled in hdrCacheInit()
return rep;
}
=== modified file 'src/HttpRequest.cc'
--- src/HttpRequest.cc 2009-11-04 12:08:08 +
+++ src/HttpRequest.cc 2010-01-26 21:07:51 +
@@ -189,7 +189,7 @@
// 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;
@@ -357,6 +357,7 @@
{
HttpMsg::hdrCacheInit();
+assert(!range);
range = header.getRange();
}