Fold the code for freeing env

Also, `e->stack = NULL` is not needed.
This is because "use-after-free" can be detected with `MRB_DEBUG` + `MRB_GC_STRESS`.
This commit is contained in:
dearblue
2024-04-07 20:45:10 +09:00
parent 307812ff20
commit 1a9282914e
+2 -6
View File
@@ -761,13 +761,9 @@ obj_free(mrb_state *mrb, struct RBasic *obj, mrb_bool end)
{
struct REnv *e = (struct REnv*)obj;
if (MRB_ENV_ONSTACK_P(e)) {
/* cannot be freed */
e->stack = NULL;
break;
if (!MRB_ENV_ONSTACK_P(e)) {
mrb_free(mrb, e->stack);
}
mrb_free(mrb, e->stack);
e->stack = NULL;
}
break;