Skip to content

Commit

Permalink
Protect the last exception object from GC in ecall; fix #3702
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Jun 15, 2017
1 parent 357e478 commit b298e24
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/vm.c
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ ecall(mrb_state *mrb, int i)
mrb_value *self = mrb->c->stack;
struct RObject *exc;
ptrdiff_t cioff;
int ai = mrb_gc_arena_save(mrb);

if (i<0) return;
if (ci - mrb->c->cibase > MRB_FUNCALL_DEPTH_MAX) {
Expand All @@ -321,9 +322,13 @@ ecall(mrb_state *mrb, int i)
ci->target_class = p->target_class;
mrb->c->stack = mrb->c->stack + ci[-1].nregs;
exc = mrb->exc; mrb->exc = 0;
if (exc) {
mrb_gc_protect(mrb, mrb_obj_value(exc));
}
mrb_run(mrb, p, *self);
mrb->c->ci = mrb->c->cibase + cioff;
if (!mrb->exc) mrb->exc = exc;
mrb_gc_arena_restore(mrb, ai);
}

#ifndef MRB_FUNCALL_ARGC_MAX
Expand Down

0 comments on commit b298e24

Please sign in to comment.