Bug 1458166 - Remove listeners before destroying MediaStreams. r=bryce, a=RyanVM
authorAndreas Pehrson <pehrsons@mozilla.com>
Mon, 07 May 2018 11:36:35 +0200
changeset 470756 8ed61558ac0256d0304f45784eb76250418849ba
parent 470755 3da1d132f3832a77bcd8bdd6d68e6f151aba5764
child 470757 47f7391d2bb0cdfea0cd05c91ed30a2fc067f6ee
push id9217
push userryanvm@gmail.com
push dateSun, 13 May 2018 19:18:47 +0000
treeherdermozilla-beta@43bcbb69db21 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbryce, RyanVM
bugs1458166
milestone61.0
Bug 1458166 - Remove listeners before destroying MediaStreams. r=bryce, a=RyanVM If listeners are still registered to a MediaStream on MediaStream::Destroy (triggered by MediaStream::UnregisterUser below), they will catch and act on further events from the MediaStream (such as a track ending). This may dispatch runnables that are unnecessary since we know we are shutting down. If we first remove the listeners from the MediaStream we will never see said events. MozReview-Commit-ID: IZ1kENqL2C8
dom/media/DOMMediaStream.cpp
--- a/dom/media/DOMMediaStream.cpp
+++ b/dom/media/DOMMediaStream.cpp
@@ -450,20 +450,26 @@ DOMMediaStream::~DOMMediaStream()
   Destroy();
 }
 
 void
 DOMMediaStream::Destroy()
 {
   LOG(LogLevel::Debug, ("DOMMediaStream %p Being destroyed.", this));
   if (mOwnedListener) {
+    if (mOwnedStream) {
+      mOwnedStream->RemoveListener(mOwnedListener);
+    }
     mOwnedListener->Forget();
     mOwnedListener = nullptr;
   }
   if (mPlaybackListener) {
+    if (mPlaybackStream) {
+      mPlaybackStream->RemoveListener(mPlaybackListener);
+    }
     mPlaybackListener->Forget();
     mPlaybackListener = nullptr;
   }
   for (const RefPtr<TrackPort>& info : mTracks) {
     // We must remove ourselves from each track's principal change observer list
     // before we die. CC may have cleared info->mTrack so guard against it.
     MediaStreamTrack* track = info->GetTrack();
     if (track) {