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

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

Issue 2776473003: Clear out prefinalizer-allocated vector for conservative GC safety. (Closed)
Patch Set: improve comment 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..b7033388b0955200e2e4bf375dae2a4198d8c704 100644
--- a/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
+++ b/third_party/WebKit/Source/platform/mediastream/MediaStreamSource.cpp
@@ -61,6 +61,23 @@ 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),
+ // _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.
+ //
+ // TODO(sof): consider adding run-time checks that disallows this kind
+ // of dead object revivification by default.
+ for (size_t i = 0; i < observers.size(); ++i)
+ 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