Bug 1452472 - Guard against stopped source and removed listener after timer fired. r=jib
authorAndreas Pehrson <pehrsons@mozilla.com>
Mon, 09 Apr 2018 13:53:32 +0200
changeset 457368 3b6ab919411b5a21854c99b28b60b0116e1fada0
parent 457367 3caf84f6c8f5ab9d167d7c45299052c30f8653ab
child 457369 9daab48cb181e45db80d3ee9a4970abef5d18c48
push id153
push userfmarier@mozilla.com
push dateTue, 10 Apr 2018 02:28:40 +0000
reviewersjib
bugs1452472
milestone61.0a1
Bug 1452472 - Guard against stopped source and removed listener after timer fired. r=jib MozReview-Commit-ID: 72M3xpbOgXP
dom/media/MediaManager.cpp
--- a/dom/media/MediaManager.cpp
+++ b/dom/media/MediaManager.cpp
@@ -4283,16 +4283,26 @@ SourceListener::SetEnabledFor(TrackID aT
       MOZ_ASSERT(state.mOperationInProgress,
                  "It's our responsibility to reset the inProgress state");
 
       LOG(("SourceListener %p %s %s track %d - starting device operation",
            this, aEnable ? "enabling" : "disabling",
            aTrackID == kAudioTrack ? "audio" : "video",
            aTrackID));
 
+      if (mRemoved) {
+        // Listener was removed between timer resolving and this runnable.
+        return DeviceOperationPromise::CreateAndResolve(NS_ERROR_ABORT, __func__);
+      }
+
+      if (state.mStopped) {
+        // Source was stopped between timer resolving and this runnable.
+        return DeviceOperationPromise::CreateAndResolve(NS_ERROR_ABORT, __func__);
+      }
+
       state.mDeviceEnabled = aEnable;
 
       if (mWindowListener) {
         mWindowListener->ChromeAffectingStateChanged();
       }
 
       if (!state.mOffWhileDisabled) {
         // If the feature to turn a device off while disabled is itself disabled