]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Fixed BodyPipe.cc:144 "!theConsumer" assertion.
authorAlex Rousskov <rousskov@measurement-factory.com>
Sun, 19 Dec 2010 03:51:48 +0000 (20:51 -0700)
committerAlex Rousskov <rousskov@measurement-factory.com>
Sun, 19 Dec 2010 03:51:48 +0000 (20:51 -0700)
BodySink must hold a pointer to the body pipe it is consuming. Otherwise, the
pipe may be deleted before BodySink received the final notification and had a
chance to stop consumption, causing the assertion in the pipe destructor.

src/BodyPipe.cc

index 31922952b166efd2d868cd4fe283ca4e8917ea25..d503ff46edba5e307d42f789856eb1cb63fb71b6 100644 (file)
@@ -10,24 +10,25 @@ CBDATA_CLASS_INIT(BodyPipe);
 // data from a BodyPipe
 class BodySink: public BodyConsumer
 {
-    bool done;
 public:
-    BodySink():AsyncJob("BodySink"), done(false) {}
-    virtual ~BodySink() {}
+    BodySink(const BodyPipe::Pointer &bp): AsyncJob("BodySink"), body_pipe(bp) {}
+    virtual ~BodySink() { assert(!body_pipe); }
 
     virtual void noteMoreBodyDataAvailable(BodyPipe::Pointer bp) {
         size_t contentSize = bp->buf().contentSize();
         bp->consume(contentSize);
     }
     virtual void noteBodyProductionEnded(BodyPipe::Pointer bp) {
-        stopConsumingFrom(bp);
-        done = true;
+        stopConsumingFrom(body_pipe);
     }
     virtual void noteBodyProducerAborted(BodyPipe::Pointer bp) {
-        stopConsumingFrom(bp);
-        done = true;
+        stopConsumingFrom(body_pipe);
     }
-    bool doneAll() const {return done && AsyncJob::doneAll();}
+    bool doneAll() const {return !body_pipe && AsyncJob::doneAll();}
+
+private:
+    BodyPipe::Pointer body_pipe; ///< the pipe we are consuming from
+
     CBDATA_CLASS2(BodySink);
 };
 
@@ -318,7 +319,7 @@ BodyPipe::startAutoConsumption()
 {
     Must(mustAutoConsume);
     Must(!theConsumer);
-    theConsumer = new BodySink;
+    theConsumer = new BodySink(this);
     debugs(91,7, HERE << "starting auto consumption" << status());
     scheduleBodyDataNotification();
 }