ruby-changes:48655
From: ko1 <ko1@a...>
Date: Wed, 15 Nov 2017 13:52:55 +0900 (JST)
Subject: [ruby-changes:48655] ko1:r60771 (trunk): fix uninitialized memory reference.
ko1 2017-11-15 13:52:39 +0900 (Wed, 15 Nov 2017) New Revision: 60771 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=60771 Log: fix uninitialized memory reference. * compile.c (iseq_set_sequence): clear kwargs (in ci_entries) memory area. kwargs ci entries are initialized by compiler. However, sometimes these initializations are skipped because corresponding calls are eliminated by some optimizations (for example, `if true` syntax elimnates else code). Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 60770) +++ test/ruby/test_optimization.rb (revision 60771) @@ -647,4 +647,19 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L647 eval "def foo; 1.times{|(a), &b| nil && a}; end" END end + + def test_clear_unreachable_keyword_args + assert_separately [], <<-END + script = <<-EOS + if true + else + foo(k1:1) + end + EOS + GC.stress = true + 30.times{ + RubyVM::InstructionSequence.compile(script) + } + END + end end Index: compile.c =================================================================== --- compile.c (revision 60770) +++ compile.c (revision 60771) @@ -1939,6 +1939,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L1939 iseq->body->is_entries = ZALLOC_N(union iseq_inline_storage_entry, iseq->body->is_size); iseq->body->ci_entries = (struct rb_call_info *)ruby_xmalloc(sizeof(struct rb_call_info) * iseq->body->ci_size + sizeof(struct rb_call_info_with_kwarg) * iseq->body->ci_kw_size); + MEMZERO(iseq->body->ci_entries + iseq->body->ci_size, struct rb_call_info_with_kwarg, iseq->body->ci_kw_size); /* need to clear ci_kw entries */ iseq->body->cc_entries = ZALLOC_N(struct rb_call_cache, iseq->body->ci_size + iseq->body->ci_kw_size); ISEQ_COMPILE_DATA(iseq)->ci_index = ISEQ_COMPILE_DATA(iseq)->ci_kw_index = 0; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/