From 27321290d954300192c82cdf5e2c794a695473f5 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 6 Jun 2024 20:02:12 +0900 Subject: [PATCH] [Bug #20521] ripper: Clean up strterm --- parse.y | 3 +++ test/ripper/test_lexer.rb | 27 ++++++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/parse.y b/parse.y index 94288b2ef8..8e59c87f0c 100644 --- a/parse.y +++ b/parse.y @@ -15668,6 +15668,9 @@ rb_ruby_parser_free(void *ptr) st_free_table(p->case_labels); } + xfree(p->lex.strterm); + p->lex.strterm = 0; + xfree(ptr); } diff --git a/test/ripper/test_lexer.rb b/test/ripper/test_lexer.rb index 392c4e9cba..64b4336375 100644 --- a/test/ripper/test_lexer.rb +++ b/test/ripper/test_lexer.rb @@ -253,18 +253,31 @@ world" assert_equal(code, Ripper.tokenize(code).join(""), bug) end + InvalidHeredocInsideBlockParam = <<~CODE + a do |b + <<-C + C + | + end + CODE + def test_heredoc_inside_block_param bug = '[Bug #19399]' - code = <<~CODE - a do |b - <<-C - C - | - end - CODE + code = InvalidHeredocInsideBlockParam assert_equal(code, Ripper.tokenize(code).join(""), bug) end + def test_heredoc_no_memory_leak + assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-'end;'}", rss: true) + require "ripper" + source = "" #{InvalidHeredocInsideBlockParam.dump} + begin; + 400_000.times do + Ripper.new(source).parse + end + end; + end + def test_heredoc_unterminated_interpolation code = <<~'HEREDOC' <