Skip to content

Commit 7d2ae9f

Browse files
committed
fix(gc): Mark call frames and open upvalues as roots to prevent use-after-free crashes
1 parent b7e2324 commit 7d2ae9f

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/runtime/gc.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,16 @@ static void markRoots() {
154154
markValue(*slot);
155155
}
156156

157+
// 2. Mark Frames (Function Closures)
158+
for (int i = 0; i < vm.frameCount; i++) {
159+
markObject((Obj*)vm.frames[i].closure);
160+
}
161+
162+
// 3. Mark Open Upvalues
163+
for (ObjUpvalue* upvalue = vm.openUpvalues; upvalue != NULL; upvalue = upvalue->next) {
164+
markObject((Obj*)upvalue);
165+
}
166+
157167
// 2. Mark Globals
158168
markTable(&vm.globals);
159169

0 commit comments

Comments
 (0)