diff --git a/prism_compile.c b/prism_compile.c index 63893c5184..c71c1429b2 100644 --- a/prism_compile.c +++ b/prism_compile.c @@ -1265,6 +1265,7 @@ pm_new_child_iseq(rb_iseq_t *iseq, pm_scope_node_t *node, VALUE name, const rb_i type, ISEQ_COMPILE_DATA(iseq)->option, &error_state); if (error_state) { + pm_scope_node_destroy(node); RUBY_ASSERT(ret_iseq == NULL); rb_jump_tag(error_state); } diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 37b23e8db5..72a0d821a0 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -337,6 +337,19 @@ class TestAst < Test::Unit::TestCase assert_parse("END {defined? yield}") end + def test_invalid_yield_no_memory_leak + # [Bug #21383] + assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-'end;'}", rss: true) + code = proc do + eval("class C; yield; end") + rescue SyntaxError + end + 1_000.times(&code) + begin; + 100_000.times(&code) + end; + end + def test_node_id_for_location omit if ParserSupport.prism_enabled?