ruby-changes:32932
From: nagachika <ko1@a...>
Date: Mon, 17 Feb 2014 01:47:31 +0900 (JST)
Subject: [ruby-changes:32932] nagachika:r45011 (ruby_2_0_0): merge revision(s) r43942, r43957, r43975: [Backport #9187]
nagachika 2014-02-17 01:47:24 +0900 (Mon, 17 Feb 2014) New Revision: 45011 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45011 Log: 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] Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/hash.c branches/ruby_2_0_0/test/ruby/test_hash.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 45010) +++ ruby_2_0_0/ChangeLog (revision 45011) @@ -1,3 +1,20 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Mon Feb 17 01:41:59 2014 Masaki Matsushita <glass.saga@g...> + + * array.c (rb_hash_rehash): use hash_alloc() instead of rb_hash_new(). + [Bug #9187] + +Mon Feb 17 01:41:59 2014 Masaki Matsushita <glass.saga@g...> + + * 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. + +Mon Feb 17 01:41:59 2014 Masaki Matsushita <glass.saga@g...> + + * hash.c (rb_hash_rehash): fix to free new st_table when exception + is raised in do_hash(). [Bug #9187] + Mon Feb 17 01:18:04 2014 Nobuyoshi Nakada <nobu@r...> * eval.c (rb_mod_s_constants): return its own constants for other Index: ruby_2_0_0/hash.c =================================================================== --- ruby_2_0_0/hash.c (revision 45010) +++ ruby_2_0_0/hash.c (revision 45011) @@ -480,6 +480,11 @@ rb_hash_s_try_convert(VALUE dummy, VALUE https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/hash.c#L480 return rb_check_hash_type(hash); } +struct rehash_arg { + VALUE hash; + st_table *tbl; +}; + static int rb_hash_rehash_i(VALUE key, VALUE value, VALUE arg) { @@ -512,6 +517,7 @@ rb_hash_rehash_i(VALUE key, VALUE value, https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/hash.c#L517 static VALUE rb_hash_rehash(VALUE hash) { + VALUE tmp; st_table *tbl; if (RHASH_ITER_LEV(hash) > 0) { @@ -520,10 +526,14 @@ rb_hash_rehash(VALUE hash) https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/hash.c#L526 rb_hash_modify_check(hash); if (!RHASH(hash)->ntbl) return hash; + tmp = hash_alloc(0); tbl = st_init_table_with_size(RHASH(hash)->ntbl->type, RHASH(hash)->ntbl->num_entries); + RHASH(tmp)->ntbl = tbl; + rb_hash_foreach(hash, rb_hash_rehash_i, (VALUE)tbl); st_free_table(RHASH(hash)->ntbl); RHASH(hash)->ntbl = tbl; + RHASH(tmp)->ntbl = 0; return hash; } Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 45010) +++ ruby_2_0_0/version.h (revision 45011) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-02-17" -#define RUBY_PATCHLEVEL 429 +#define RUBY_PATCHLEVEL 430 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_0_0/test/ruby/test_hash.rb =================================================================== --- ruby_2_0_0/test/ruby/test_hash.rb (revision 45010) +++ ruby_2_0_0/test/ruby/test_hash.rb (revision 45011) @@ -993,6 +993,34 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_hash.rb#L993 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 Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r43942,43957,43975 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/