Bug 1742334 - Make sure to null out ChannelEventQueue::mOwner when object is released r=necko-reviewers,dragana

Differential Revision: https://phabricator.services.mozilla.com/D131896
This commit is contained in:
Valentin Gosu 2021-12-07 21:32:03 +00:00
Родитель e935b21fac
Коммит 5e575d631e
7 изменённых файлов: 20 добавлений и 1 удалений

Просмотреть файл

@ -34,7 +34,11 @@ void ChannelEventQueue::FlushQueue() {
// Events flushed could include destruction of channel (and our own // Events flushed could include destruction of channel (and our own
// destructor) unless we make sure its refcount doesn't drop to 0 while this // destructor) unless we make sure its refcount doesn't drop to 0 while this
// method is running. // method is running.
nsCOMPtr<nsISupports> kungFuDeathGrip(mOwner); nsCOMPtr<nsISupports> kungFuDeathGrip;
{
MutexAutoLock lock(mMutex);
kungFuDeathGrip = mOwner;
}
mozilla::Unused << kungFuDeathGrip; // Not used in this function mozilla::Unused << kungFuDeathGrip; // Not used in this function
#ifdef DEBUG #ifdef DEBUG
@ -156,6 +160,10 @@ void ChannelEventQueue::ResumeInternal() {
nsCOMPtr<nsISupports> mOwner; nsCOMPtr<nsISupports> mOwner;
}; };
if (!mOwner) {
return;
}
// Worker thread requires a CancelableRunnable. // Worker thread requires a CancelableRunnable.
RefPtr<Runnable> event = new CompleteResumeRunnable(this, mOwner); RefPtr<Runnable> event = new CompleteResumeRunnable(this, mOwner);

Просмотреть файл

@ -147,6 +147,11 @@ class ChannelEventQueue final {
// dispatched in a new event on the current thread. // dispatched in a new event on the current thread.
void Resume(); void Resume();
void NotifyReleasingOwner() {
MutexAutoLock lock(mMutex);
mOwner = nullptr;
}
#ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED #ifdef MOZ_DIAGNOSTIC_ASSERT_ENABLED
bool IsEmpty() const { return mEventQueue.IsEmpty(); } bool IsEmpty() const { return mEventQueue.IsEmpty(); }
#endif #endif

Просмотреть файл

@ -141,6 +141,8 @@ HttpChannelChild::~HttpChannelChild() {
} }
#endif #endif
mEventQ->NotifyReleasingOwner();
ReleaseMainThreadOnlyReferences(); ReleaseMainThreadOnlyReferences();
} }

Просмотреть файл

@ -107,6 +107,7 @@ HttpChannelParent::~HttpChannelParent() {
mRedirectCallback->OnRedirectVerifyCallback(NS_ERROR_UNEXPECTED); mRedirectCallback->OnRedirectVerifyCallback(NS_ERROR_UNEXPECTED);
mRedirectCallback = nullptr; mRedirectCallback = nullptr;
} }
mEventQ->NotifyReleasingOwner();
} }
void HttpChannelParent::ActorDestroy(ActorDestroyReason why) { void HttpChannelParent::ActorDestroy(ActorDestroyReason why) {

Просмотреть файл

@ -84,6 +84,7 @@ HttpTransactionParent::HttpTransactionParent(bool aIsDocumentLoad)
HttpTransactionParent::~HttpTransactionParent() { HttpTransactionParent::~HttpTransactionParent() {
LOG(("Destroying HttpTransactionParent @%p\n", this)); LOG(("Destroying HttpTransactionParent @%p\n", this));
mEventQ->NotifyReleasingOwner();
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

Просмотреть файл

@ -66,6 +66,7 @@ WebSocketChannelChild::WebSocketChannelChild(bool aEncrypted)
WebSocketChannelChild::~WebSocketChannelChild() { WebSocketChannelChild::~WebSocketChannelChild() {
LOG(("WebSocketChannelChild::~WebSocketChannelChild() %p\n", this)); LOG(("WebSocketChannelChild::~WebSocketChannelChild() %p\n", this));
mEventQ->NotifyReleasingOwner();
} }
void WebSocketChannelChild::AddIPDLReference() { void WebSocketChannelChild::AddIPDLReference() {

Просмотреть файл

@ -108,6 +108,7 @@ StreamFilterParent::~StreamFilterParent() {
NS_ReleaseOnMainThread("StreamFilterParent::mOrigListener", NS_ReleaseOnMainThread("StreamFilterParent::mOrigListener",
mOrigListener.forget()); mOrigListener.forget());
NS_ReleaseOnMainThread("StreamFilterParent::mContext", mContext.forget()); NS_ReleaseOnMainThread("StreamFilterParent::mContext", mContext.forget());
mQueue->NotifyReleasingOwner();
} }
auto StreamFilterParent::Create(dom::ContentParent* aContentParent, auto StreamFilterParent::Create(dom::ContentParent* aContentParent,