Skip to content

Commit 406e3d3

Browse files
committed
Initialize visited on copied interpreter frames
_PyFrame_Copy() copied interpreter frames into generator and frame-object storage without initializing the visited byte. Incremental GC later reads frame->visited in mark_stacks() on non-start passes, so copied frames could expose an uninitialized value once they became live on a thread stack again. Reset visited when copying a frame so copied frames start with defined GC bookkeeping state. Preserve lltrace in Py_DEBUG builds.
1 parent b07becb commit 406e3d3

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Include/internal/pycore_interpframe.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,11 @@ static inline void _PyFrame_Copy(_PyInterpreterFrame *src, _PyInterpreterFrame *
149149
int stacktop = (int)(src->stackpointer - src->localsplus);
150150
assert(stacktop >= 0);
151151
dest->stackpointer = dest->localsplus + stacktop;
152+
// visited is GC bookkeeping for the current stack walk, not frame state.
153+
dest->visited = 0;
154+
#ifdef Py_DEBUG
155+
dest->lltrace = src->lltrace;
156+
#endif
152157
for (int i = 0; i < stacktop; i++) {
153158
dest->localsplus[i] = PyStackRef_MakeHeapSafe(src->localsplus[i]);
154159
}

0 commit comments

Comments
 (0)