Title: [271296] trunk
Revision
271296
Author
[email protected]
Date
2021-01-08 07:45:20 -0800 (Fri, 08 Jan 2021)

Log Message

Make it safe to re-enter HashMap::clear()
https://bugs.webkit.org/show_bug.cgi?id=220445

Reviewed by Geoffrey Garen.

Source/WTF:

Make it safe to re-enter HashMap::clear(). This will fix some crashes on the GPUProcess bots
due to DisplayList::clear() re-entering via HashMap::clear().

* wtf/HashTable.h:
(WTF::KeyTraits>::clear):

Tools:

Add API test coverage.

* TestWebKitAPI/Tests/WTF/HashMap.cpp:
(TestWebKitAPI::TEST):

Modified Paths

Diff

Modified: trunk/Source/WTF/ChangeLog (271295 => 271296)


--- trunk/Source/WTF/ChangeLog	2021-01-08 15:26:34 UTC (rev 271295)
+++ trunk/Source/WTF/ChangeLog	2021-01-08 15:45:20 UTC (rev 271296)
@@ -1,3 +1,16 @@
+2021-01-08  Chris Dumez  <[email protected]>
+
+        Make it safe to re-enter HashMap::clear()
+        https://bugs.webkit.org/show_bug.cgi?id=220445
+
+        Reviewed by Geoffrey Garen.
+
+        Make it safe to re-enter HashMap::clear(). This will fix some crashes on the GPUProcess bots
+        due to DisplayList::clear() re-entering via HashMap::clear().
+
+        * wtf/HashTable.h:
+        (WTF::KeyTraits>::clear):
+
 2021-01-07  Commit Queue  <[email protected]>
 
         Unreviewed, reverting r271192.

Modified: trunk/Source/WTF/wtf/HashTable.h (271295 => 271296)


--- trunk/Source/WTF/wtf/HashTable.h	2021-01-08 15:26:34 UTC (rev 271295)
+++ trunk/Source/WTF/wtf/HashTable.h	2021-01-08 15:45:20 UTC (rev 271296)
@@ -1380,8 +1380,7 @@
         if (!m_table)
             return;
 
-        deallocateTable(m_table);
-        m_table = nullptr;
+        deallocateTable(std::exchange(m_table, nullptr));
     }
 
     template<typename Key, typename Value, typename Extractor, typename HashFunctions, typename Traits, typename KeyTraits>

Modified: trunk/Tools/ChangeLog (271295 => 271296)


--- trunk/Tools/ChangeLog	2021-01-08 15:26:34 UTC (rev 271295)
+++ trunk/Tools/ChangeLog	2021-01-08 15:45:20 UTC (rev 271296)
@@ -1,3 +1,15 @@
+2021-01-08  Chris Dumez  <[email protected]>
+
+        Make it safe to re-enter HashMap::clear()
+        https://bugs.webkit.org/show_bug.cgi?id=220445
+
+        Reviewed by Geoffrey Garen.
+
+        Add API test coverage.
+
+        * TestWebKitAPI/Tests/WTF/HashMap.cpp:
+        (TestWebKitAPI::TEST):
+
 2021-01-08  Chris Lord  <[email protected]>
 
         [WPE] Enable smooth-motion and kinetic scrolling on touchpads

Modified: trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp (271295 => 271296)


--- trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2021-01-08 15:26:34 UTC (rev 271295)
+++ trunk/Tools/TestWebKitAPI/Tests/WTF/HashMap.cpp	2021-01-08 15:45:20 UTC (rev 271296)
@@ -1163,4 +1163,36 @@
     }
 }
 
+class TestObjectWithCustomDestructor {
+    WTF_MAKE_FAST_ALLOCATED;
+public:
+    TestObjectWithCustomDestructor(Function<void()>&& runInDestructor)
+        : m_runInDestructor(WTFMove(runInDestructor))
+    { }
+
+    ~TestObjectWithCustomDestructor()
+    {
+        m_runInDestructor();
+    }
+
+private:
+    Function<void()> m_runInDestructor;
+};
+
+TEST(WTF_HashMap, Clear_Reenter)
+{
+    HashMap<uint64_t, std::unique_ptr<TestObjectWithCustomDestructor>> map;
+    for (unsigned i = 1; i <= 10; ++i) {
+        map.add(i, makeUnique<TestObjectWithCustomDestructor>([&map] {
+            map.clear();
+            EXPECT_EQ(0U, map.size());
+            EXPECT_TRUE(map.isEmpty());
+        }));
+    }
+    EXPECT_EQ(10U, map.size());
+    map.clear();
+    EXPECT_EQ(0U, map.size());
+    EXPECT_TRUE(map.isEmpty());
+}
+
 } // namespace TestWebKitAPI
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to