diff --git a/compile.c b/compile.c index c270308acc..ca998bef15 100644 --- a/compile.c +++ b/compile.c @@ -1939,6 +1939,7 @@ iseq_set_sequence(rb_iseq_t *iseq, LINK_ANCHOR *const anchor) 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; diff --git a/test/ruby/test_optimization.rb b/test/ruby/test_optimization.rb index 40015c57dd..3ea867e8e1 100644 --- a/test/ruby/test_optimization.rb +++ b/test/ruby/test_optimization.rb @@ -647,4 +647,19 @@ class TestRubyOptimization < Test::Unit::TestCase 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