Bug 1332845 - Remove listeners before other cleanup in MediaRecorder. r=jesup, a=gchang
authorAndreas Pehrson <pehrsons@gmail.com>
Fri, 07 Apr 2017 16:50:55 +0200
changeset 396054 43dc349fa417b02371b4bd0723bb6eea9b68f6d3
parent 396053 64901233ef75b97857c049e6193c06d4cf03de9e
child 396055 74f3c44c94f2854f0aea1606ec73b8ef53b43da7
push id1468
push userasasaki@mozilla.com
push dateMon, 05 Jun 2017 19:31:07 +0000
treeherdermozilla-release@0641fc6ee9d1 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjesup, gchang
bugs1332845
milestone54.0
Bug 1332845 - Remove listeners before other cleanup in MediaRecorder. r=jesup, a=gchang There was an indirect race from destroying this MediaInputPort before removing the direct listener. MozReview-Commit-ID: 7rPzsLL4EvG
dom/media/MediaRecorder.cpp
--- a/dom/media/MediaRecorder.cpp
+++ b/dom/media/MediaRecorder.cpp
@@ -820,21 +820,16 @@ private:
   void CleanupStreams()
   {
     if (mInputStream) {
       if (mEncoder) {
         mInputStream->RemoveDirectListener(mEncoder.get());
       }
       mInputStream = nullptr;
     }
-    for (RefPtr<MediaInputPort>& inputPort : mInputPorts) {
-      MOZ_ASSERT(inputPort);
-      inputPort->Destroy();
-    }
-    mInputPorts.Clear();
 
     if (mTrackUnionStream) {
       if (mEncoder) {
         nsTArray<RefPtr<mozilla::dom::VideoStreamTrack>> videoTracks;
         DOMMediaStream* domStream = mRecorder->Stream();
         if (domStream) {
           domStream->GetVideoTracks(videoTracks);
           if (!videoTracks.IsEmpty()) {
@@ -850,16 +845,22 @@ private:
       }
       if (mEncoder) {
         mTrackUnionStream->RemoveListener(mEncoder.get());
       }
       mTrackUnionStream->Destroy();
       mTrackUnionStream = nullptr;
     }
 
+    for (RefPtr<MediaInputPort>& inputPort : mInputPorts) {
+      MOZ_ASSERT(inputPort);
+      inputPort->Destroy();
+    }
+    mInputPorts.Clear();
+
     if (mMediaStream) {
       mMediaStream->UnregisterTrackListener(this);
       mMediaStream = nullptr;
     }
 
     for (RefPtr<MediaStreamTrack>& track : mMediaStreamTracks) {
       track->RemovePrincipalChangeObserver(this);
     }