From d6a4cd77f20db875a5c3550df1909a589ad31ecf Mon Sep 17 00:00:00 2001 From: Randell Jesup Date: Thu, 9 Jul 2015 23:21:46 -0400 Subject: [PATCH] Bug 1155059: Patch 8 - Don't leak runnables when MediaCache/FileBlockCache get shut down after XPCOM is in final shutdown r=cpearce --- dom/media/FileBlockCache.cpp | 13 ++++++++++--- dom/media/MediaCache.cpp | 10 ++++++++-- 2 files changed, 18 insertions(+), 5 deletions(-) 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