vm.c (OP_ENTER): fix issues by unreferenced kdict and blk

There's short a period where kdict and blk are not pointed from the stack.
This commit is contained in:
Yukihiro "Matz" Matsumoto
2023-05-23 14:54:36 +09:00
parent 2f7f797473
commit 8f745b7728
+6 -3
View File
@@ -2101,6 +2101,8 @@ RETRY_TRY_BLOCK:
else {
mrb_int rnum = 0;
if (argv0 != argv) {
mrb_gc_protect(mrb, blk);
mrb_gc_protect(mrb, kdict);
value_move(&regs[1], argv, m1+o);
}
if (r) {
@@ -2117,11 +2119,12 @@ RETRY_TRY_BLOCK:
/* need to be update blk first to protect blk from GC */
mrb_int const kw_pos = len + kd; /* where kwhash should be */
mrb_int const blk_pos = kw_pos + 1; /* where block should be */
regs[blk_pos] = blk; /* move block */
regs[blk_pos] = blk; /* move block */
if (kd) {
if (mrb_nil_p(kdict))
if (mrb_nil_p(kdict)) {
kdict = mrb_hash_new_capa(mrb, 0);
regs[kw_pos] = kdict; /* set kwhash */
}
regs[kw_pos] = kdict; /* set kwhash */
ci->nk = 15;
}