Skip to content

Commit

Permalink
Avoid underflow of rb_yjit_live_iseq_count
Browse files Browse the repository at this point in the history
This value is only incremented when rb_iseq_translate_threaded_code is
called, which doesn't happen for iseqs which result in a syntax error.

This is easy to hit by running a debug build with RUBY_FREE_AT_EXIT=1,
but any build and options could underflow this value by running enough
evals.
  • Loading branch information
jhawthorn committed Dec 22, 2023
1 parent cae11dd commit c18edc5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
10 changes: 10 additions & 0 deletions bootstraptest/test_eval.rb
Expand Up @@ -227,6 +227,16 @@ def initialize &b
}, '[ruby-dev:31372]'
end

assert_normal_exit %{
$stderr = STDOUT
5000.times do
begin
eval "0 rescue break"
rescue SyntaxError
end
end
}

assert_normal_exit %q{
$stderr = STDOUT
class Foo
Expand Down
6 changes: 4 additions & 2 deletions iseq.c
Expand Up @@ -167,8 +167,10 @@ rb_iseq_free(const rb_iseq_t *iseq)
rb_rjit_free_iseq(iseq); /* Notify RJIT */
#if USE_YJIT
rb_yjit_iseq_free(body->yjit_payload);
RUBY_ASSERT(rb_yjit_live_iseq_count > 0);
rb_yjit_live_iseq_count--;
if (FL_TEST_RAW((VALUE)iseq, ISEQ_TRANSLATED)) {
RUBY_ASSERT(rb_yjit_live_iseq_count > 0);
rb_yjit_live_iseq_count--;
}
#endif
ruby_xfree((void *)body->iseq_encoded);
ruby_xfree((void *)body->insns_info.body);
Expand Down

0 comments on commit c18edc5

Please sign in to comment.