diff --git a/ChangeLog b/ChangeLog index 9fa0f70f08..5ea93de880 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Wed Jan 13 16:56:19 2016 Nobuyoshi Nakada + + * iseq.c (rb_iseq_mark): mark parent iseq to prevent dynamically + generated iseq by eval from GC. [ruby-core:72620] [Bug #11928] + Wed Jan 13 03:42:58 2016 Eric Wong * class.c (Init_class_hierarchy): resolve name for rb_cObject ASAP @@ -9,12 +14,6 @@ Wed Jan 13 00:37:12 2016 Satoshi Ohmori * man/ruby.1: fix double word typo. [Fix GH-1194] -Wed Jan 13 00:16:47 2016 Nobuyoshi Nakada - - * iseq.c (iseqw_mark): as wrapped iseq is isolated from the call - stack, it needs to take care of its parent and ancestors, so - that they do not become orphans. [ruby-core:72620] [Bug #11928] - Tue Jan 12 21:01:09 2016 Benoit Daloze * common.mk: update URL and name for the Ruby spec suite. diff --git a/iseq.c b/iseq.c index 8b75ac6cbd..b8ae57b782 100644 --- a/iseq.c +++ b/iseq.c @@ -113,6 +113,7 @@ rb_iseq_mark(const rb_iseq_t *iseq) rb_gc_mark(body->location.base_label); rb_gc_mark(body->location.path); RUBY_MARK_UNLESS_NULL(body->location.absolute_path); + RUBY_MARK_UNLESS_NULL((VALUE)body->parent_iseq); } if (FL_TEST(iseq, ISEQ_NOT_LOADED_YET)) { @@ -711,11 +712,7 @@ rb_iseq_coverage(const rb_iseq_t *iseq) static void iseqw_mark(void *ptr) { - const rb_iseq_t *iseq = ptr; rb_gc_mark((VALUE)ptr); - while ((iseq = iseq->body->parent_iseq) != NULL) { - rb_gc_mark((VALUE)iseq); - } } static size_t diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb index 4f7616a0db..7af8c1b11b 100644 --- a/test/ruby/test_iseq.rb +++ b/test/ruby/test_iseq.rb @@ -185,4 +185,31 @@ class TestISeq < Test::Unit::TestCase labels = body.select {|op, arg| op == :branchnil}.map {|op, arg| arg} assert_equal(1, labels.uniq.size) end + + def test_parent_iseq_mark + assert_separately([], <<-'end;') + ->{ + ->{ + ->{ + eval <<-EOS + class Segfault + define_method :segfault do + x = nil + GC.disable + 1000.times do |n| + n.times do + x = (foo rescue $!).local_variables + end + GC.start + end + x + end + end + EOS + }.call + }.call + }.call + at_exit { assert_equal([:n, :x], Segfault.new.segfault.sort) } + end; + end end