Commit 6b517cee authored by Alex Chronopoulos's avatar Alex Chronopoulos
Browse files

Bug 1616086 - Avoid modifying the Active Windows hash table when an iterator is accessing it. r=jib

In order to stop the SourceListeners, first collect them in an array and stop them outside the loop. The `StopRawID` method modifies indirectly the mActiveWindows and will assert-carsh since the iterator is active and the table is enumerated.

Differential Revision: https://phabricator.services.mozilla.com/D63100

--HG--
extra : moz-landing-system : lando
parent 9e1daa29
Loading
Loading
Loading
Loading
+10 −2
Original line number Diff line number Diff line
@@ -2185,10 +2185,18 @@ void MediaManager::DeviceListChanged() {
                // Device has not been removed
                continue;
              }
              // Stop the corresponding SourceListener
              // Stop the corresponding SourceListener. In order to do that
              // first collect the listeners in an array and stop them after
              // the loop. The StopRawID method modify indirectly the
              // mActiveWindows and will assert-crash since the iterator is
              // active and the table is being enumerated.
              nsTArray<RefPtr<GetUserMediaWindowListener>> stopListeners;
              for (auto iter = mActiveWindows.Iter(); !iter.Done();
                   iter.Next()) {
                iter.UserData()->StopRawID(id);
                stopListeners.AppendElement(iter.UserData());
              }
              for (auto& l : stopListeners) {
                l->StopRawID(id);
              }
            }
            mDeviceIDs = deviceIDs;