Skip to content

Commit cdb039d

Browse files
committed
merge revision(s) 9f91f36: [Backport #21383]
Fix memory leak with invalid yield in prism [Bug #21383] The following script leaks memory: 10.times do 20_000.times do eval("class C; yield; end") rescue SyntaxError end puts `ps -o rss= -p #{$$}` end Before: 16464 25536 29424 35904 39552 44576 46736 51600 56096 59824 After: 13488 16160 18240 20528 19760 21808 21680 22272 22064 22336
1 parent 1bdae34 commit cdb039d

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

prism_compile.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1265,6 +1265,7 @@ pm_new_child_iseq(rb_iseq_t *iseq, pm_scope_node_t *node, VALUE name, const rb_i
12651265
type, ISEQ_COMPILE_DATA(iseq)->option, &error_state);
12661266

12671267
if (error_state) {
1268+
pm_scope_node_destroy(node);
12681269
RUBY_ASSERT(ret_iseq == NULL);
12691270
rb_jump_tag(error_state);
12701271
}

test/ruby/test_ast.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,6 +337,19 @@ def test_invalid_yield
337337
assert_parse("END {defined? yield}")
338338
end
339339

340+
def test_invalid_yield_no_memory_leak
341+
# [Bug #21383]
342+
assert_no_memory_leak([], "#{<<-"begin;"}", "#{<<-'end;'}", rss: true)
343+
code = proc do
344+
eval("class C; yield; end")
345+
rescue SyntaxError
346+
end
347+
1_000.times(&code)
348+
begin;
349+
100_000.times(&code)
350+
end;
351+
end
352+
340353
def test_node_id_for_location
341354
omit if ParserSupport.prism_enabled?
342355

version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
1212
#define RUBY_VERSION_TEENY 4
1313
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
14-
#define RUBY_PATCHLEVEL 36
14+
#define RUBY_PATCHLEVEL 37
1515

1616
#include "ruby/version.h"
1717
#include "ruby/internal/abi.h"

0 commit comments

Comments
 (0)