Skip to content

Commit

Permalink
[Bug #20941] Bail out when recursing no memory
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Dec 11, 2024
1 parent 80038b9 commit 2f43887
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
7 changes: 7 additions & 0 deletions gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -4446,6 +4446,13 @@ rb_memerror(void)
EC_JUMP_TAG(ec, TAG_RAISE);
}

bool
rb_gc_reentered(void)
{
rb_execution_context_t *ec = GET_EC();
return (ec && rb_ec_raised_p(ec, RAISED_NOMEMORY));
}

void
rb_malloc_info_show_results(void)
{
Expand Down
3 changes: 3 additions & 0 deletions gc/default/default.c
Original file line number Diff line number Diff line change
Expand Up @@ -2470,6 +2470,9 @@ newobj_slowpath(VALUE klass, VALUE flags, rb_objspace_t *objspace, rb_ractor_new
if (during_gc) {
dont_gc_on();
during_gc = 0;
if (rb_gc_reentered()) {
rb_memerror();
}
rb_bug("object allocation during garbage collection phase");
}

Expand Down
1 change: 1 addition & 0 deletions gc/gc.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ uint32_t rb_gc_rebuild_shape(VALUE obj, size_t heap_id);
size_t rb_obj_memsize_of(VALUE obj);
void rb_gc_prepare_heap_process_object(VALUE obj);
bool ruby_free_at_exit_p(void);
bool rb_gc_reentered(void);

#if USE_MODULAR_GC
bool rb_gc_event_hook_required_p(rb_event_flag_t event);
Expand Down

0 comments on commit 2f43887

Please sign in to comment.