Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detach env of ci explicitly on atexit #6288

Merged
merged 1 commit into from
Jun 9, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -592,10 +592,33 @@ mrb_protect_atexit(mrb_state *mrb)
// Clean-up also makes it easier to collect unnecessary objects.
mrb_callinfo zero = { 0 };
struct mrb_context *c = mrb->c = mrb->root_c;
c->ci = c->cibase;
*c->ci = zero;
c->ci->stack = c->stbase;
mrb_gc_arena_restore(mrb, 0);

if (c->ci == c->cibase) {
// Since there is no problem with the ci, the env object is detached normally.
struct REnv *e = mrb_vm_ci_env(c->ci);
*c->ci = zero;
c->ci->stack = c->stbase;
if (e) {
c->ci->u.env = NULL;
mrb_env_unshare(mrb, e, TRUE);
}
}
else {
// Any env objects on the ci that are in the process of being executed are destroyed.
do {
struct REnv *e = mrb_vm_ci_env(c->ci);
if (e) {
e->stack = NULL;
MRB_ENV_SET_LEN(e, 0);
MRB_ENV_SET_BIDX(e, 0);
MRB_ENV_CLOSE(e);
}
} while (c->ci-- > c->cibase);
c->ci = c->cibase;
*c->ci = zero;
c->ci->stack = c->stbase;
}
}

struct mrb_jmpbuf *prev_jmp = mrb->jmp;
Expand Down