mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
gc.c (mrb_gc_register): protect obj from GC during execution
Because `mrb_ary_new()` and `mrb_ary_push()` can cause GC; fix #6317
This commit is contained in:
@@ -418,11 +418,14 @@ mrb_gc_register(mrb_state *mrb, mrb_value obj)
|
||||
|
||||
if (mrb_immediate_p(obj)) return;
|
||||
table = mrb_gv_get(mrb, GC_ROOT_SYM);
|
||||
int ai = mrb_gc_arena_save(mrb);
|
||||
mrb_gc_protect(mrb, obj);
|
||||
if (mrb_nil_p(table) || !mrb_array_p(table)) {
|
||||
table = mrb_ary_new(mrb);
|
||||
mrb_gv_set(mrb, GC_ROOT_SYM, table);
|
||||
}
|
||||
mrb_ary_push(mrb, table, obj);
|
||||
mrb_gc_arena_restore(mrb, ai);
|
||||
}
|
||||
|
||||
/* mrb_gc_unregister() removes the object from GC root. */
|
||||
|
||||
Reference in New Issue
Block a user