summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2017-06-15 14:54:29 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2017-06-15 14:57:18 +0900
commitb298e241c82b72a84b6f852e435b0f2f38cfbb42 (patch)
tree630ce1691a3960c97c5df6d114439551c30b504f /src
parent357e478e2cf9f4c695dea1b5efbc3783225576ee (diff)
downloadmruby-b298e241c82b72a84b6f852e435b0f2f38cfbb42.tar.gz
mruby-b298e241c82b72a84b6f852e435b0f2f38cfbb42.zip
Protect the last exception object from GC in `ecall`; fix #3702
Diffstat (limited to 'src')
-rw-r--r--src/vm.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/vm.c b/src/vm.c
index 419b93be1..e3460d742 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -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) {
@@ -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