Index: third_party/WebKit/Source/wtf/ThreadSpecific.h |
diff --git a/third_party/WebKit/Source/wtf/ThreadSpecific.h b/third_party/WebKit/Source/wtf/ThreadSpecific.h |
index 5d7f6d26a9eba250c76907a791b1e34b80de2c5d..377a82f4e24e405aafb5c707a672de58ddc39ce6 100644 |
--- a/third_party/WebKit/Source/wtf/ThreadSpecific.h |
+++ b/third_party/WebKit/Source/wtf/ThreadSpecific.h |
@@ -224,11 +224,6 @@ inline void ThreadSpecific<T>::set(T* ptr) { |
template <typename T> |
inline void ThreadSpecific<T>::destroy(void* ptr) { |
- // Never call destructors on the main thread. |
- // This is fine because Blink no longer has a graceful shutdown sequence. |
- if (isMainThread()) |
- return; |
- |
Data* data = static_cast<Data*>(ptr); |
#if OS(POSIX) |
@@ -238,6 +233,13 @@ inline void ThreadSpecific<T>::destroy(void* ptr) { |
pthread_setspecific(data->owner->m_key, ptr); |
#endif |
+ // Never call destructors on the main thread. This is fine because Blink no |
+ // longer has a graceful shutdown sequence. Be careful to call this function |
+ // (which can be re-entrant) while the pointer is still set, to avoid lazily |
+ // allocating WTFThreadData after it is destroyed. |
+ if (isMainThread()) |
+ return; |
+ |
data->value->~T(); |
Partitions::fastFree(data->value); |