Avoid double free() of env stack; fix #3860

Should turn on `MRB_ENV_STACK_UNSHARED` flag only after env stack
reallocation.  `malloc()` may fail.
parent d3e273ba
......@@ -283,12 +283,12 @@ mrb_env_unshare(mrb_state *mrb, struct REnv *e)
if (!MRB_ENV_STACK_SHARED_P(e)) return;
if (e->cxt != mrb->c) return;
MRB_ENV_UNSHARE_STACK(e);
p = (mrb_value *)mrb_malloc(mrb, sizeof(mrb_value)*len);
if (len > 0) {
stack_copy(p, e->stack, len);
}
e->stack = p;
MRB_ENV_UNSHARE_STACK(e);
mrb_write_barrier(mrb, (struct RBasic *)e);
}
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment