Skip to content

Commit 636946f

Browse files
[3.14] gh-148144: Initialize visited on copied interpreter frames (GH-148143) (#148147)
gh-148144: Initialize visited on copied interpreter frames (GH-148143) _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. (cherry picked from commit fbfc6cc) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent e99b801 commit 636946f

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

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
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Initialize ``_PyInterpreterFrame.visited`` when copying interpreter frames so
2+
incremental GC does not read an uninitialized byte from generator and
3+
frame-object copies.

0 commit comments

Comments
 (0)