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

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

Issue 2776473003: Clear out prefinalizer-allocated vector for conservative GC safety. (Closed)
Patch Set: Created 3 years, 9 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 | « no previous file | 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 79485a8d4989a5457b2b396d089fd757a61b617a..8b64be54ef6ef674b44373889609afb9ef893f26 100644
--- a/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
+++ b/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
@@ -61,6 +61,20 @@ void MediaStreamSource::setReadyState(ReadyState readyState) {
copyToVector(m_observers, observers);
for (auto observer : observers)
observer->sourceChangedState();
+
+ // setReadyState() will be invoked via the MediaStreamComponent::dispose(),
+ // prefinalizer, allocating |observers|. Which means that |observers| will
+ // live until the next/ GC (but be unreferenced by other heap objects),
haraken 2017/03/24 04:58:43 next
+ // _but_ it will potentially contain references to Observers that were
+ // GCed after the MediaStreamComponent prefinalizer had completed.
+ //
+ // So, if the next GC is a conservative one _and_ it happens to find
+ // a reference to |observers| when scanning the stack, we're in trouble
+ // as it contains references to now-dead objects.
+ //
+ // Work around this by explicitly clearing the vector backing store.
+ for (size_t i = 0; i < observers.size(); ++i)
haraken 2017/03/24 04:58:43 Can we just call observers.clear()?
sof 2017/03/24 05:03:25 We need to clear the backing store contents, not w
+ observers[i] = nullptr;
}
}
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698