]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
HttpHeaderEntry leaks and HttpHeader::len corruption by delById().
authorAlex Rousskov <rousskov@measurement-factory.com>
Wed, 18 May 2016 05:21:28 +0000 (23:21 -0600)
committerAlex Rousskov <rousskov@measurement-factory.com>
Wed, 18 May 2016 05:21:28 +0000 (23:21 -0600)
AFAICT, this regression was introduced in trunk r14285 (Refactor
HttpHeader into gperf-generated perfect hash) and became severe after
trunk r14659 started calling delById() on virtually every request.

src/HttpHeader.cc

index 9be069dab3a1711eab13ad8ba2c81380f01c26d8..0f9b965f4e7da329fe104244cb8e8e704c0bc355 100644 (file)
@@ -595,21 +595,17 @@ HttpHeader::delById(Http::HdrType id)
 {
     debugs(55, 8, this << " del-by-id " << id);
     assert(any_registered_header(id));
-    int count=0;
 
     if (!CBIT_TEST(mask, id))
         return 0;
 
-    //replace matching items with nil and count them
-    std::replace_if(entries.begin(), entries.end(),
-    [&](const HttpHeaderEntry *e) {
-        if (e && e->id == id) {
-            ++count;
-            return true;
-        }
-        return false;
-    },
-    nullptr);
+    int count = 0;
+
+    HttpHeaderPos pos = HttpHeaderInitPos;
+    while (HttpHeaderEntry *e = getEntry(&pos)) {
+        if (e->id == id)
+            delAt(pos, count); // deletes e
+    }
 
     CBIT_CLR(mask, id);
     assert(count);