diff --git a/sources/Data/Collections/HashTable.uc b/sources/Data/Collections/HashTable.uc index 2435a88..5cf9aa8 100644 --- a/sources/Data/Collections/HashTable.uc +++ b/sources/Data/Collections/HashTable.uc @@ -394,7 +394,7 @@ public final function HashTable SetItem( if (value != none) { value.NewRef(); } - if (oldEntry.value != none && newEntry.value != oldEntry.value) { + if (oldEntry.value != none) { oldEntry.value.FreeSelf(); } hashTable[bucketIndex].entries[entryIndex] = newEntry; diff --git a/sources/Data/Collections/Tests/TEST_HashTable.uc b/sources/Data/Collections/Tests/TEST_HashTable.uc index 3ec2ccc..66b461e 100644 --- a/sources/Data/Collections/Tests/TEST_HashTable.uc +++ b/sources/Data/Collections/Tests/TEST_HashTable.uc @@ -26,6 +26,7 @@ var private array mockedItems; protected static function TESTS() { Test_GetSet(); + Test_Rewrite(); Test_HasKey(); Test_GetKeys(); Test_GetTextKeys(); @@ -89,6 +90,21 @@ protected static function Test_GetSet() TEST_ExpectNone(array.GetItem(__().text.FromString("Some random stuff"))); } +protected static function Test_Rewrite() +{ + local Text textObject; + local HashTable array; + + array = HashTable(__().memory.Allocate(class'HashTable')); + Context("Testing getters and setters for items of `HashTable`."); + Issue("`SetItem()` does not handle reference counts correctly when" + @ "replacing a value with itself."); + textObject = __().text.FromString("value"); + array.SetItem(__().text.FromString("key"), textObject); + array.SetItem(__().text.FromString("key"), textObject); + TEST_ExpectTrue(textObject._getRefCount() == 2); +} + protected static function Test_HasKey() { local HashTable array;