Fixed possible inconsistency in gc_protect()

If `mrb_realloc()` raises an out-of-memory exception, `arena_capa` will hold the wrong value.
This commit is contained in:
dearblue
2022-06-14 22:31:45 +09:00
parent 561dffcccc
commit cbeb392d7d
+3 -2
View File
@@ -459,8 +459,9 @@ gc_protect(mrb_state *mrb, mrb_gc *gc, struct RBasic *p)
#else
if (gc->arena_idx >= gc->arena_capa) {
/* extend arena */
gc->arena_capa = (int)(gc->arena_capa * 3 / 2);
gc->arena = (struct RBasic**)mrb_realloc(mrb, gc->arena, sizeof(struct RBasic*)*gc->arena_capa);
int newcapa = gc->arena_capa * 3 / 2;
gc->arena = (struct RBasic**)mrb_realloc(mrb, gc->arena, sizeof(struct RBasic*)*newcapa);
gc->arena_capa = newcapa;
}
#endif
gc->arena[gc->arena_idx++] = p;