Skip to content

Commit

Permalink
pythongh-118272: set stacktop to 0 before freeing contents, to avoid …
Browse files Browse the repository at this point in the history
…access to invalid objects during GC (python#118478)
  • Loading branch information
iritkatriel authored May 1, 2024
1 parent 1161ab9 commit 6763bfc
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Python/frame.c
Original file line number Diff line number Diff line change
Expand Up @@ -98,10 +98,11 @@ void
_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
{
assert(frame->stacktop >= 0);
for (int i = 0; i < frame->stacktop; i++) {
int stacktop = frame->stacktop;
frame->stacktop = 0;
for (int i = 0; i < stacktop; i++) {
Py_XDECREF(frame->localsplus[i]);
}
frame->stacktop = 0;
Py_CLEAR(frame->f_locals);
}

Expand Down

0 comments on commit 6763bfc

Please sign in to comment.