From 1a9282914edacfe3c8d5c1366e1aacfe2d2893fc Mon Sep 17 00:00:00 2001 From: dearblue Date: Sun, 7 Apr 2024 20:45:10 +0900 Subject: [PATCH] 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`. --- src/gc.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/gc.c b/src/gc.c index 533722a9b..f3c7e3c6b 100644 --- a/src/gc.c +++ b/src/gc.c @@ -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;