Skip to content

Commit 6763bfc

Browse files
authored
gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid objects during GC (#118478)
1 parent 1161ab9 commit 6763bfc

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Python/frame.c

+3-2
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ void
9898
_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
9999
{
100100
assert(frame->stacktop >= 0);
101-
for (int i = 0; i < frame->stacktop; i++) {
101+
int stacktop = frame->stacktop;
102+
frame->stacktop = 0;
103+
for (int i = 0; i < stacktop; i++) {
102104
Py_XDECREF(frame->localsplus[i]);
103105
}
104-
frame->stacktop = 0;
105106
Py_CLEAR(frame->f_locals);
106107
}
107108

0 commit comments

Comments
 (0)