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

Unified Diff: third_party/WebKit/Source/platform/heap/PersistentNode.h

Issue 1964013002: Handle overlapping CrossThreadPersistent<> releases. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: drop unneeded PLATFORM_EXPORTs Created 4 years, 7 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
Index: third_party/WebKit/Source/platform/heap/PersistentNode.h
diff --git a/third_party/WebKit/Source/platform/heap/PersistentNode.h b/third_party/WebKit/Source/platform/heap/PersistentNode.h
index 7bbae43f15681a50c158e50971baf2ef13e245e3..4775fd5f4ef8ad92a04c9a3a9b14fc1ef4629702 100644
--- a/third_party/WebKit/Source/platform/heap/PersistentNode.h
+++ b/third_party/WebKit/Source/platform/heap/PersistentNode.h
@@ -174,16 +174,26 @@ class CrossThreadPersistentRegion final {
public:
CrossThreadPersistentRegion() : m_persistentRegion(adoptPtr(new PersistentRegion)) { }
- PersistentNode* allocatePersistentNode(void* self, TraceCallback trace)
+ void allocatePersistentNode(PersistentNode*& persistentNode, void* self, TraceCallback trace)
{
MutexLocker lock(m_mutex);
- return m_persistentRegion->allocatePersistentNode(self, trace);
+ persistentNode = m_persistentRegion->allocatePersistentNode(self, trace);
}
- void freePersistentNode(PersistentNode* persistentNode)
+ void freePersistentNode(PersistentNode*& persistentNode)
{
MutexLocker lock(m_mutex);
+ // When the thread that holds the heap object that the cross-thread persistent shuts down,
+ // prepareForThreadStateTermination() will clear out the associated CrossThreadPersistent<>
+ // and PersistentNode so as to avoid unsafe access. This can overlap with a holder of
+ // the CrossThreadPersistent<> also clearing the persistent and freeing the PersistentNode.
+ //
+ // The lock ensures the updating is ordered, but by the time lock has been acquired the
+ // PersistentNode reference may have been cleared out already; check for this.
+ if (!persistentNode)
+ return;
m_persistentRegion->freePersistentNode(persistentNode);
+ persistentNode = nullptr;
}
void tracePersistentNodes(Visitor* visitor)
« no previous file with comments | « third_party/WebKit/Source/platform/heap/Handle.h ('k') | third_party/WebKit/Source/platform/heap/PersistentNode.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698