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.
--- 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;
}