gh-118272: set stacktop to 0 before freeing contents, to avoid access to invalid objects during GC (#118478)

This commit is contained in:
Irit Katriel 2024-05-01 21:51:40 +01:00 committed by GitHub
parent 1161ab9085
commit 6763bfcc0f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 2 deletions

View File

@ -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);
}