Skip to content

Commit

Permalink
Protect arguments from GC; fix #3597
Browse files Browse the repository at this point in the history
GC may be called with OP_ENTER (especially when GC_STRESS is set).
  • Loading branch information
matz committed Apr 10, 2017
1 parent a55b237 commit 0048dd1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
8 changes: 7 additions & 1 deletion src/gc.c
Expand Up @@ -545,10 +545,16 @@ mark_context_stack(mrb_state *mrb, struct mrb_context *c)
size_t i;
size_t e;
mrb_value nil;
int nregs;

if (c->stack == NULL) return;
e = c->stack - c->stbase;
if (c->ci) e += c->ci->nregs;
if (c->ci) {
nregs = c->ci->argc + 2;
if (c->ci->nregs > nregs)
nregs = c->ci->nregs;
e += nregs;
}
if (c->stbase + e > c->stend) e = c->stend - c->stbase;
for (i=0; i<e; i++) {
mrb_value v = c->stbase[i];
Expand Down
2 changes: 1 addition & 1 deletion src/vm.c
Expand Up @@ -1589,7 +1589,6 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
argc = mrb_ary_ptr(argv[0])->len;
argv = mrb_ary_ptr(argv[0])->ptr;
}
mrb->c->ci->argc = len;
if (argc < len) {
int mlen = m2;
if (argc < m1+m2) {
Expand Down Expand Up @@ -1639,6 +1638,7 @@ mrb_vm_exec(mrb_state *mrb, struct RProc *proc, mrb_code *pc)
}
pc += o + 1;
}
mrb->c->ci->argc = len;
/* clear local (but non-argument) variables */
if (irep->nlocals-len-2 > 0) {
stack_clear(&regs[len+2], irep->nlocals-len-2);
Expand Down

0 comments on commit 0048dd1

Please sign in to comment.