Skip to content

Commit 31502b0

Browse files
XrXrtenderlove
authored andcommitted
Have ast live longer in ISeq.compile_file to fix GC stress crash
Previously, live range of `ast_value` ended on the call right before rb_ast_dispose(), which led to premature collection and use-after-free. We observed this crashing on -O3, -DVM_CHECK_MODE, with GCC 11.4.0 on Ubuntu. Co-authored-by: Aaron Patterson <[email protected]>
1 parent 5cc4398 commit 31502b0

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

iseq.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,7 @@ iseqw_s_compile_file(int argc, VALUE *argv, VALUE self)
17491749
1, NULL, 0, ISEQ_TYPE_TOP, &option,
17501750
Qnil));
17511751
rb_ast_dispose(ast);
1752+
RB_GC_GUARD(ast_value);
17521753

17531754
rb_vm_pop_frame(ec);
17541755
RB_GC_GUARD(v);

test/ruby/test_iseq.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -919,4 +919,10 @@ def test_while_in_until_condition
919919
assert_predicate(status, :success?)
920920
end
921921
end
922+
923+
def test_compile_empty_under_gc_stress
924+
EnvUtil.under_gc_stress do
925+
RubyVM::InstructionSequence.compile_file(File::NULL)
926+
end
927+
end
922928
end

0 commit comments

Comments
 (0)