summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorAlan Wu <XrXr@users.noreply.github.com>2023-12-13 12:11:49 -0500
committerAaron Patterson <aaron.patterson@gmail.com>2023-12-13 09:43:09 -0800
commita3b48ac9ad8a5d4eb7ae6c3d4fe9d040361daa7a (patch)
tree8ba63cf9d53755779eff6cfd30d41711abfc1b8d /test/ruby
parentcc86fa8416b571e2d833157b852dee31a0d2f731 (diff)
Fix memory leak in Hash#compare_by_identity
We didn't free the old ST before overwriting it which caused a leak. Found with RUBY_FREE_ON_EXIT. Co-authored-by: Peter Zhu <peter@peterzhu.ca>
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_hash.rb8
1 files changed, 8 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb
index 639707d8eb..8658e6ddc2 100644
--- a/test/ruby/test_hash.rb
+++ b/test/ruby/test_hash.rb
@@ -1909,6 +1909,14 @@ class TestHashOnly < Test::Unit::TestCase
end;
end
+ def test_compare_by_id_memory_leak
+ assert_no_memory_leak([], "", <<~RUBY, rss: true)
+ 1_000_000.times do
+ {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8}.compare_by_identity
+ end
+ RUBY
+ end
+
def test_try_convert
assert_equal({1=>2}, Hash.try_convert({1=>2}))
assert_equal(nil, Hash.try_convert("1=>2"))