Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(251)

Unified Diff: third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp

Issue 1885053002: Safely iterate over MediaStreamSource observers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: add test Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-observer-iterate-no-crash-expected.txt ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
diff --git a/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp b/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
index 5819964562478268e9b9749276a3aee6f48efd36..62d5a02a47bc9fc08de87b58109c99fc945b0fd0 100644
--- a/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
+++ b/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
@@ -53,8 +53,13 @@ void MediaStreamSource::setReadyState(ReadyState readyState)
{
if (m_readyState != ReadyStateEnded && m_readyState != readyState) {
m_readyState = readyState;
- for (auto i = m_observers.begin(); i != m_observers.end(); ++i)
- (*i)->sourceChangedState();
+
+ // Observers may dispatch events which create and add new Observers;
+ // take a snapshot so as to safely iterate.
+ HeapVector<Member<Observer>> observers;
+ copyToVector(m_observers, observers);
+ for (auto observer : observers)
+ observer->sourceChangedState();
}
}
« no previous file with comments | « third_party/WebKit/LayoutTests/fast/mediastream/MediaStreamTrack-observer-iterate-no-crash-expected.txt ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698