]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Bug 4919: master commit b599471 leaks memory (#364) M-staged-PR364
authorAlex Rousskov <rousskov@measurement-factory.com>
Thu, 14 Feb 2019 18:48:56 +0000 (18:48 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Thu, 14 Feb 2019 21:21:32 +0000 (21:21 +0000)
Restored the natural order of the following two notifications:
* BodyConsumer::noteMoreBodyDataAvailable() and
* BodyConsumer::noteBodyProductionEnded() or noteBodyProducerAborted().

Commit b599471 unintentionally reordered those two notifications. Client
kids (and possibly other BodyConsumers) relied on the natural order to
end their work. If an HttpStateData job was done with the Squid-to-peer
connection and only waiting for the last adapted body bytes, it would
get stuck and leak many objects. This use case was not tested during
b599471 work.

src/BodyPipe.cc

index 551f0a53831c4044bee0007d231f314390ec7d7b..69b49ad4a5b92e835a0f7ace8b2e3139ad956154 100644 (file)
@@ -397,13 +397,15 @@ BodyPipe::postAppend(size_t size)
     thePutSize += size;
     debugs(91,7, HERE << "added " << size << " bytes" << status());
 
-    if (!mayNeedMoreData())
-        clearProducer(true); // reached end-of-body
-
     // We should not consume here even if mustAutoConsume because the
     // caller may not be ready for the data to be consumed during this call.
     scheduleBodyDataNotification();
 
+    // Do this check after scheduleBodyDataNotification() to ensure the
+    // natural order of "more body data" and "production ended" events.
+    if (!mayNeedMoreData())
+        clearProducer(true); // reached end-of-body
+
     startAutoConsumptionIfNeeded();
 }