From 664dc2670410b8498b550b3c0402ab61992e615b Mon Sep 17 00:00:00 2001 From: Alex Rousskov Date: Thu, 14 Feb 2019 18:48:56 +0000 Subject: [PATCH] Bug 4919: master commit b599471 leaks memory (#364) 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 | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/BodyPipe.cc b/src/BodyPipe.cc index 551f0a5383..69b49ad4a5 100644 --- a/src/BodyPipe.cc +++ b/src/BodyPipe.cc @@ -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(); } -- 2.47.2