Bug 1320346 - dump |rv| when AddBlocker() fails to get more debugging info. r?cpearce draft
authorJW Wang <jwwang@mozilla.com>
Tue, 29 Nov 2016 10:38:32 +0800
changeset 445321 f7a1dcc9982c0e0a0d008f5d5e74599c2fdc2a96
parent 445186 234a7ec9d28778046bd19f9e218a19618a2e9b21
child 538489 910713ec9f874a3314682d92a5f5096ea0034546
push id37480
push userjwwang@mozilla.com
push dateTue, 29 Nov 2016 12:16:23 +0000
reviewerscpearce
bugs1320346
milestone53.0a1
Bug 1320346 - dump |rv| when AddBlocker() fails to get more debugging info. r?cpearce MozReview-Commit-ID: LA3uPvdKCU5
dom/media/MediaShutdownManager.cpp
--- a/dom/media/MediaShutdownManager.cpp
+++ b/dom/media/MediaShutdownManager.cpp
@@ -69,32 +69,41 @@ MediaShutdownManager::EnsureCorrectShutd
 {
   bool needShutdownObserver = mDecoders.Count() > 0;
   if (needShutdownObserver != mIsObservingShutdown) {
     mIsObservingShutdown = needShutdownObserver;
     if (mIsObservingShutdown) {
       nsresult rv = GetShutdownBarrier()->AddBlocker(
         this, NS_LITERAL_STRING(__FILE__), __LINE__,
         NS_LITERAL_STRING("MediaShutdownManager shutdown"));
-      MOZ_RELEASE_ASSERT(NS_SUCCEEDED(rv));
+      if (NS_FAILED(rv)) {
+        // Leak the buffer on the heap to make sure that it lives long enough,
+        // as MOZ_CRASH_ANNOTATE expects the pointer passed to it to live to
+        // the end of the program.
+        const size_t CAPACITY = 256;
+        auto buf = new char[CAPACITY];
+        snprintf(buf, CAPACITY, "Failed to add shutdown blocker! rv=%x", uint32_t(rv));
+        MOZ_CRASH_ANNOTATE(buf);
+        MOZ_REALLY_CRASH();
+      }
     } else {
       GetShutdownBarrier()->RemoveBlocker(this);
       // Clear our singleton reference. This will probably delete
       // this instance, so don't deref |this| clearing sInstance.
       sInstance = nullptr;
       DECODER_LOG(LogLevel::Debug, ("MediaShutdownManager::BlockShutdown() end."));
     }
   }
 }
 
 void
 MediaShutdownManager::Register(MediaDecoder* aDecoder)
 {
   MOZ_ASSERT(NS_IsMainThread());
-  MOZ_DIAGNOSTIC_ASSERT(!mIsDoingXPCOMShutDown);
+  MOZ_RELEASE_ASSERT(!mIsDoingXPCOMShutDown);
   // Don't call Register() after you've Unregistered() all the decoders,
   // that's not going to work.
   MOZ_ASSERT(!mDecoders.Contains(aDecoder));
   mDecoders.PutEntry(aDecoder);
   MOZ_ASSERT(mDecoders.Contains(aDecoder));
   MOZ_ASSERT(mDecoders.Count() > 0);
   EnsureCorrectShutdownObserverState();
 }