From 886142e8eecec4956b4f5d1d3fa8761dba1cd7d1 Mon Sep 17 00:00:00 2001 From: nagachika Date: Sun, 16 Feb 2014 16:47:24 +0000 Subject: merge revision(s) r43942,r43957,r43975: [Backport #9187] * hash.c (rb_hash_rehash): fix to free new st_table when exception is raised in do_hash(). [Bug #9187] * hash.c (rb_hash_rehash): make temporary st_table under the control of GC. [Bug #9187] * test/ruby/test_hash.rb: add a test for above. * array.c (rb_hash_rehash): use hash_alloc() instead of rb_hash_new(). [Bug #9187] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@45011 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'test') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index c84ee74adf..a77c5cf43f 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -993,6 +993,34 @@ class TestHash < Test::Unit::TestCase end end + def test_exception_in_rehash + bug9187 = '[ruby-core:58728] [Bug #9187]' + + prepare = <<-EOS + class Foo + def initialize + @raise = false + end + + def hash + raise if @raise + @raise = true + return 0 + end + end + EOS + + code = <<-EOS + h = {Foo.new => true} + 10_0000.times do + h.rehash rescue nil + end + GC.start + EOS + + assert_no_memory_leak([], prepare, code, bug9187) + end + class TestSubHash < TestHash class SubHash < Hash end -- cgit v1.2.3