diff --git a/netwerk/ipc/ChannelEventQueue.h b/netwerk/ipc/ChannelEventQueue.h index d4a7aca9ed05..a843decabca1 100644 --- a/netwerk/ipc/ChannelEventQueue.h +++ b/netwerk/ipc/ChannelEventQueue.h @@ -52,10 +52,10 @@ class ChannelEventQueue final // automatically when EndForcedQueueing and/or Resume is called. // // @param aCallback - the ChannelEvent - // @param aAssertWhenNotQueued - this optional param will be used in an + // @param aAssertionWhenNotQueued - this optional param will be used in an // assertion when the event is executed directly. inline void RunOrEnqueue(ChannelEvent* aCallback, - bool aAssertWhenNotQueued = true); + bool aAssertionWhenNotQueued = false); inline nsresult PrependEvents(nsTArray>& aEvents); // After StartForcedQueueing is called, RunOrEnqueue() will start enqueuing @@ -109,10 +109,13 @@ class ChannelEventQueue final inline void ChannelEventQueue::RunOrEnqueue(ChannelEvent* aCallback, - bool aAssertWhenNotQueued) + bool aAssertionWhenNotQueued) { MOZ_ASSERT(aCallback); + // To avoid leaks. + UniquePtr event(aCallback); + { MutexAutoLock lock(mMutex); @@ -121,13 +124,13 @@ ChannelEventQueue::RunOrEnqueue(ChannelEvent* aCallback, "Should always enqueue if ChannelEventQueue not empty"); if (enqueue) { - mEventQueue.AppendElement(aCallback); + mEventQueue.AppendElement(Move(event)); return; } } - MOZ_RELEASE_ASSERT(aAssertWhenNotQueued); - aCallback->Run(); + MOZ_RELEASE_ASSERT(!aAssertionWhenNotQueued); + event->Run(); } inline void diff --git a/netwerk/protocol/ftp/FTPChannelChild.cpp b/netwerk/protocol/ftp/FTPChannelChild.cpp index dfb1d89d2601..b83a695a4395 100644 --- a/netwerk/protocol/ftp/FTPChannelChild.cpp +++ b/netwerk/protocol/ftp/FTPChannelChild.cpp @@ -377,7 +377,7 @@ FTPChannelChild::RecvOnDataAvailable(const nsresult& channelStatus, mEventQ->RunOrEnqueue(new FTPDataAvailableEvent(this, channelStatus, data, offset, count), - !mDivertingToParent); + mDivertingToParent); return true; } @@ -632,7 +632,7 @@ FTPChannelChild::RecvFlushedForDiversion() LOG(("FTPChannelChild::RecvFlushedForDiversion [this=%p]\n", this)); MOZ_ASSERT(mDivertingToParent); - mEventQ->RunOrEnqueue(new FTPFlushedForDiversionEvent(this)); + mEventQ->RunOrEnqueue(new FTPFlushedForDiversionEvent(this), true); return true; } diff --git a/netwerk/protocol/http/HttpChannelChild.cpp b/netwerk/protocol/http/HttpChannelChild.cpp index 21658344d7ad..b765808a0fd4 100644 --- a/netwerk/protocol/http/HttpChannelChild.cpp +++ b/netwerk/protocol/http/HttpChannelChild.cpp @@ -611,7 +611,7 @@ HttpChannelChild::RecvOnTransportAndData(const nsresult& channelStatus, transportStatus, progress, progressMax, data, offset, count), - !mDivertingToParent); + mDivertingToParent); return true; } @@ -810,7 +810,8 @@ HttpChannelChild::RecvOnStopRequest(const nsresult& channelStatus, MOZ_RELEASE_ASSERT(!mFlushedForDiversion, "Should not be receiving any more callbacks from parent!"); - mEventQ->RunOrEnqueue(new StopRequestEvent(this, channelStatus, timing)); + mEventQ->RunOrEnqueue(new StopRequestEvent(this, channelStatus, timing), + mDivertingToParent); return true; } @@ -1339,7 +1340,7 @@ HttpChannelChild::RecvFlushedForDiversion() LOG(("HttpChannelChild::RecvFlushedForDiversion [this=%p]\n", this)); MOZ_RELEASE_ASSERT(mDivertingToParent); - mEventQ->RunOrEnqueue(new HttpFlushedForDiversionEvent(this)); + mEventQ->RunOrEnqueue(new HttpFlushedForDiversionEvent(this), true); return true; }