diff --git a/dom/media/MediaCache.cpp b/dom/media/MediaCache.cpp index 06cb1aae7bede..2a022d2838026 100644 --- a/dom/media/MediaCache.cpp +++ b/dom/media/MediaCache.cpp @@ -268,15 +268,6 @@ class MediaCache uint32_t mNext; }; - // Called during shutdown to clear sThread. - void operator=(std::nullptr_t) - { - nsCOMPtr thread = sThread.forget(); - if (thread) { - thread->Shutdown(); - } - } - protected: explicit MediaCache(MediaBlockCacheBase* aCache) : mNextResourceID(1) @@ -726,10 +717,18 @@ MediaCache::GetMediaCache(int64_t aContentLength) return nullptr; } sThread = thread.forget(); - // Note it is safe to pass an invalid pointer for operator=(std::nullptr_t) - // is non-virtual and it will not access |this|. - ClearOnShutdown(reinterpret_cast(0x1), - ShutdownPhase::ShutdownThreads); + + static struct ClearThread + { + // Called during shutdown to clear sThread. + void operator=(std::nullptr_t) + { + nsCOMPtr thread = sThread.forget(); + MOZ_ASSERT(thread); + thread->Shutdown(); + } + } sClearThread; + ClearOnShutdown(&sClearThread, ShutdownPhase::ShutdownThreads); } if (!sThread) {