[Bug #20521] ripper: Clean up strterm

This commit is contained in:
Nobuyoshi Nakada 2024-06-06 20:02:12 +09:00
parent f465045dd6
commit 27321290d9
2 changed files with 23 additions and 7 deletions

View File

@ -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);
}

View File

@ -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'
<<A+1