diff --git a/dom/media/FileBlockCache.cpp b/dom/media/FileBlockCache.cpp index 6461b6fc5bea..4cc9ef219c19 100644 --- a/dom/media/FileBlockCache.cpp +++ b/dom/media/FileBlockCache.cpp @@ -74,9 +74,16 @@ void FileBlockCache::Close() // opening more streams, while the media cache is shutting down and // releasing memory etc! Also note we close mFD in the destructor so // as to not disturb any IO that's currently running. - nsCOMPtr event = new ShutdownThreadEvent(mThread); - mThread = nullptr; - NS_DispatchToMainThread(event); + nsCOMPtr mainThread = do_GetMainThread(); + if (mainThread) { + nsCOMPtr event = new ShutdownThreadEvent(mThread); + mainThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL); + } else { + // we're on Mainthread already, *and* the event queues are already + // shut down, so no events should occur - certainly not creations of + // new streams. + mThread->Shutdown(); + } } } diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index ab5248faf687..aed2a6695d13 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -1409,8 +1409,14 @@ MediaCache::QueueUpdate() if (mUpdateQueued) return; mUpdateQueued = true; - nsCOMPtr event = new UpdateEvent(); - NS_DispatchToMainThread(event); + // XXX MediaCache does updates when decoders are still running at + // shutdown and get freed in the final cycle-collector cleanup. So + // don't leak a runnable in that case. + nsCOMPtr mainThread = do_GetMainThread(); + if (mainThread) { + nsCOMPtr event = new UpdateEvent(); + mainThread->Dispatch(event.forget(), NS_DISPATCH_NORMAL); + } } void