Bug 1125776: Part11. Fix potential crash. r=mattwoodrow. a=lmandel
authorJean-Yves Avenard <jyavenard@mozilla.com>
Wed, 04 Feb 2015 20:20:16 +1100
changeset 247743 d2675abc9228bf1a17d507f805eba01571dbed83
parent 247742 bfb746be073770753b82b4a741377ceb1a18b248
child 247744 366436d0a508933169520fd2401eee9ea14e42e0
push id889
push usergijskruitbosch@gmail.com
push dateTue, 03 Mar 2015 18:12:54 +0000
reviewersmattwoodrow, lmandel
bugs1125776
milestone37.0a2
Bug 1125776: Part11. Fix potential crash. r=mattwoodrow. a=lmandel Under some circumstances, it was possible for shutdown to have completed right before the initialization task got to run. Resulting in a null dereference.
dom/media/mediasource/TrackBuffer.cpp
--- a/dom/media/mediasource/TrackBuffer.cpp
+++ b/dom/media/mediasource/TrackBuffer.cpp
@@ -480,16 +480,21 @@ TrackBuffer::QueueInitializeDecoder(Sour
     return false;
   }
   return true;
 }
 
 void
 TrackBuffer::InitializeDecoder(SourceBufferDecoder* aDecoder)
 {
+  if (!mParentDecoder) {
+    MSE_DEBUG("TrackBuffer(%p) was shutdown. Aborting initialization.",
+              this);
+    return;
+  }
   // ReadMetadata may block the thread waiting on data, so we must be able
   // to leave the monitor while we call it. For the rest of this function
   // we want to hold the monitor though, since we run on a different task queue
   // from the reader and interact heavily with it.
   mParentDecoder->GetReentrantMonitor().AssertNotCurrentThreadIn();
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
 
   if (mCurrentDecoder != aDecoder) {
@@ -582,16 +587,21 @@ TrackBuffer::InitializeDecoder(SourceBuf
     mInitializationPromise.RejectIfExists(NS_ERROR_FAILURE, __func__);
     return;
   }
 }
 
 void
 TrackBuffer::CompleteInitializeDecoder(SourceBufferDecoder* aDecoder)
 {
+  if (!mParentDecoder) {
+    MSE_DEBUG("TrackBuffer(%p) was shutdown. Aborting initialization.",
+              this);
+    return;
+  }
   ReentrantMonitorAutoEnter mon(mParentDecoder->GetReentrantMonitor());
   if (mCurrentDecoder != aDecoder) {
     MSE_DEBUG("TrackBuffer(%p) append was cancelled. Aborting initialization.",
               this);
     // If we reached this point, the SourceBuffer would have disconnected
     // the promise. So no need to reject it.
     return;
   }