diff options
-rw-r--r-- | dom/media/MediaStreamTrack.cpp | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/dom/media/MediaStreamTrack.cpp b/dom/media/MediaStreamTrack.cpp index 8ccdeb90c..75cdeb1d1 100644 --- a/dom/media/MediaStreamTrack.cpp +++ b/dom/media/MediaStreamTrack.cpp @@ -165,11 +165,15 @@ MediaStreamTrack::Destroy() mPrincipalHandleListener->Forget(); mPrincipalHandleListener = nullptr; } - for (auto l : mTrackListeners) { - RemoveListener(l); + // Remove all listeners -- avoid iterating over the list we're removing from + const nsTArray<RefPtr<MediaStreamTrackListener>> trackListeners(mTrackListeners); + for (auto listener : trackListeners) { + RemoveListener(listener); } - for (auto l : mDirectTrackListeners) { - RemoveDirectListener(l); + // Do the same as above for direct listeners + const nsTArray<RefPtr<DirectMediaStreamTrackListener>> directTrackListeners(mDirectTrackListeners); + for (auto listener : directTrackListeners) { + RemoveDirectListener(listener); } } |