[WTF] HashTable's rehash is not compatible to Ref<T> and ASan
authorutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2016 23:08:49 +0000 (23:08 +0000)
committerutatane.tea@gmail.com <utatane.tea@gmail.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Mon, 12 Sep 2016 23:08:49 +0000 (23:08 +0000)
https://bugs.webkit.org/show_bug.cgi?id=161763

Reviewed by Darin Adler.

Destructors of HashTable's empty values need to be called while ones of deleted values don't.

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

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@205836 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Source/WTF/ChangeLog
Source/WTF/wtf/HashTable.h
Source/WTF/wtf/Ref.h

index c6ac49c..75cff2d 100644 (file)
@@ -1,3 +1,16 @@
+2016-09-12  Yusuke Suzuki  <utatane.tea@gmail.com>
+
+        [WTF] HashTable's rehash is not compatible to Ref<T> and ASan
+        https://bugs.webkit.org/show_bug.cgi?id=161763
+
+        Reviewed by Darin Adler.
+
+        Destructors of HashTable's empty values need to be called while ones of deleted values don't.
+
+        * wtf/HashTable.h:
+        (WTF::KeyTraits>::deallocateTable):
+        * wtf/Ref.h:
+
 2016-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
 
         [Cocoa] Reduce uses of CGFonts in favor of CTFonts
index bce7511..a576e62 100644 (file)
@@ -1153,7 +1153,7 @@ namespace WTF {
     void HashTable<Key, Value, Extractor, HashFunctions, Traits, KeyTraits>::deallocateTable(ValueType* table, unsigned size)
     {
         for (unsigned i = 0; i < size; ++i) {
-            if (!isEmptyOrDeletedBucket(table[i]))
+            if (!isDeletedBucket(table[i]))
                 table[i].~ValueType();
         }
         fastFree(table);
@@ -1197,11 +1197,17 @@ namespace WTF {
 
         Value* newEntry = nullptr;
         for (unsigned i = 0; i != oldTableSize; ++i) {
-            if (isEmptyOrDeletedBucket(oldTable[i])) {
+            if (isDeletedBucket(oldTable[i])) {
                 ASSERT(std::addressof(oldTable[i]) != entry);
                 continue;
             }
 
+            if (isEmptyBucket(oldTable[i])) {
+                ASSERT(std::addressof(oldTable[i]) != entry);
+                oldTable[i].~ValueType();
+                continue;
+            }
+
             Value* reinsertedEntry = reinsert(WTFMove(oldTable[i]));
             oldTable[i].~ValueType();
             if (std::addressof(oldTable[i]) == entry) {
index e81b69f..47e5fa0 100644 (file)
@@ -114,7 +114,7 @@ public:
         return *this;
     }
 
-    // Hash table deleted/empty values, which are only constructed and never copied or destroyed.
+    // Hash table deleted values, which are only constructed and never copied or destroyed.
     Ref(HashTableDeletedValueType) : m_ptr(hashTableDeletedValue()) { }
     bool isHashTableDeletedValue() const { return m_ptr == hashTableDeletedValue(); }
     static T* hashTableDeletedValue() { return reinterpret_cast<T*>(-1); }