diff options
author | Peter Zhu <[email protected]> | 2023-09-22 19:16:21 -0400 |
---|---|---|
committer | Peter Zhu <[email protected]> | 2023-09-23 11:24:41 -0400 |
commit | 61a2e9450c025b6a7499719089db5b4ae0317ce6 (patch) | |
tree | 47acd17ba09747b2f708d3104d380dd2acfe4c26 /test/ruby/test_hash.rb | |
parent | d80002c902f128be11a567edafc6ef1a32ebb4d9 (diff) |
Fix memory leak in Hash#rehash for ST hashes
We need to free the old ST table in Hash#rehash.
Co-authored-by: Adam Hess <[email protected]>
Diffstat (limited to 'test/ruby/test_hash.rb')
-rw-r--r-- | test/ruby/test_hash.rb | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 9121f3539e..f95876d855 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -744,6 +744,21 @@ class TestHash < Test::Unit::TestCase assert_equal(100, h[a]) end + def test_rehash_memory_leak + assert_no_memory_leak([], <<~PREP, <<~CODE, rss: true) + ar_hash = 1.times.map { |i| [i, i] }.to_h + st_hash = 10.times.map { |i| [i, i] }.to_h + + code = proc do + ar_hash.rehash + st_hash.rehash + end + 1_000.times(&code) + PREP + 1_000_000.times(&code) + CODE + end + def test_reject assert_equal({3=>4,5=>6}, @cls[1=>2,3=>4,5=>6].reject {|k, v| k + v < 7 }) |