Bug 688516 - Null check mElement before use in NotifyDownloadEnded and AudioAvailable. r=cpearce
authorMatthew Gregan <kinetik@flim.org>
Fri, 23 Sep 2011 16:27:18 +1200
changeset 77377 27cc641828237146bdc7f92552c5bd10db62636d
parent 77376 1d41a35e38918e1636e1918c31d6b72844bd776f
child 77378 4309aaa4b59b4f0d3f4d446d7739f76b10e4780a
push id2090
push usermgregan@mozilla.com
push dateFri, 23 Sep 2011 04:52:35 +0000
treeherdermozilla-inbound@27cc64182823 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerscpearce
bugs688516
milestone9.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 688516 - Null check mElement before use in NotifyDownloadEnded and AudioAvailable. r=cpearce
content/media/nsBuiltinDecoder.cpp
content/media/nsMediaDecoder.cpp
--- a/content/media/nsBuiltinDecoder.cpp
+++ b/content/media/nsBuiltinDecoder.cpp
@@ -397,17 +397,17 @@ void nsBuiltinDecoder::AudioAvailable(fl
   // here, this ensures we free the memory. Otherwise, we pass off ownership
   // to HTMLMediaElement::NotifyAudioAvailable().
   nsAutoArrayPtr<float> frameBuffer(aFrameBuffer);
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
   if (mShuttingDown) {
     return;
   }
 
-  if (!mElement->MayHaveAudioAvailableEventListener()) {
+  if (!mElement || !mElement->MayHaveAudioAvailableEventListener()) {
     return;
   }
 
   mElement->NotifyAudioAvailable(frameBuffer.forget(), aFrameBufferLength, aTime);
 }
 
 void nsBuiltinDecoder::MetadataLoaded(PRUint32 aChannels,
                                       PRUint32 aRate)
@@ -437,18 +437,17 @@ void nsBuiltinDecoder::MetadataLoaded(PR
     // Make sure the element and the frame (if any) are told about
     // our new size.
     Invalidate();
     mElement->MetadataLoaded(aChannels, aRate);
   }
 
   if (!mResourceLoaded) {
     StartProgress();
-  }
-  else if (mElement) {
+  } else if (mElement) {
     // Resource was loaded during metadata loading, when progress
     // events are being ignored. Fire the final progress event.
     mElement->DispatchAsyncEvent(NS_LITERAL_STRING("progress"));
   }
 
   // Only inform the element of FirstFrameLoaded if not doing a load() in order
   // to fulfill a seek, otherwise we'll get multiple loadedfirstframe events.
   ReentrantMonitorAutoEnter mon(mReentrantMonitor);
@@ -659,17 +658,19 @@ void nsBuiltinDecoder::NotifyBytesDownlo
 }
 
 void nsBuiltinDecoder::NotifyDownloadEnded(nsresult aStatus)
 {
   NS_ASSERTION(NS_IsMainThread(), "Should be on main thread.");
 
   if (aStatus == NS_BINDING_ABORTED) {
     // Download has been cancelled by user.
-    mElement->LoadAborted();
+    if (mElement) {
+      mElement->LoadAborted();
+    }
     return;
   }
 
   {
     ReentrantMonitorAutoEnter mon(mReentrantMonitor);
     UpdatePlaybackRate();
   }
 
--- a/content/media/nsMediaDecoder.cpp
+++ b/content/media/nsMediaDecoder.cpp
@@ -66,17 +66,17 @@ static const PRUint32 STALL_MS = 3000;
 // ahead of the current playback position before we allow the media decoder
 // to report that it can play through the entire media without the decode
 // catching up with the download. Having this margin make the
 // nsMediaDecoder::CanPlayThrough() calculation more stable in the case of
 // fluctuating bitrates.
 static const PRInt64 CAN_PLAY_THROUGH_MARGIN = 10;
 
 nsMediaDecoder::nsMediaDecoder() :
-  mElement(0),
+  mElement(nsnull),
   mRGBWidth(-1),
   mRGBHeight(-1),
   mVideoUpdateLock("nsMediaDecoder.mVideoUpdateLock"),
   mFrameBufferLength(0),
   mPinnedForSeek(PR_FALSE),
   mSizeChanged(PR_FALSE),
   mImageContainerSizeChanged(PR_FALSE),
   mShuttingDown(PR_FALSE)