Bug 1320346 - dump |rv| when AddBlocker() fails to get more debugging info. r=cpearce
authorJW Wang <jwwang@mozilla.com>
Tue, 29 Nov 2016 10:38:32 +0800
changeset 324670 19d1b588f308767bbd3c8cc720f29b5e6ef70a3f
parent 324669 8cdeaf29cac0a8708d02e31ae1723eb0fd351a68
child 324671 b25f222b8636e91b9fb79a4c25a658bd981871a1
push id24
push usermaklebus@msu.edu
push dateTue, 20 Dec 2016 03:11:33 +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();
 }