mirror of
https://github.com/python/cpython.git
synced 2025-07-24 19:54:21 +00:00
gh-118272: Clear generator frame's locals when the generator is closed (#118277)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
This commit is contained in:
parent
f7747f73a9
commit
1f16b4ce56
5 changed files with 38 additions and 5 deletions
|
@ -94,6 +94,17 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame)
|
|||
}
|
||||
}
|
||||
|
||||
void
|
||||
_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
|
||||
{
|
||||
assert(frame->stacktop >= 0);
|
||||
for (int i = 0; i < frame->stacktop; i++) {
|
||||
Py_XDECREF(frame->localsplus[i]);
|
||||
}
|
||||
frame->stacktop = 0;
|
||||
Py_CLEAR(frame->f_locals);
|
||||
}
|
||||
|
||||
void
|
||||
_PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
|
||||
{
|
||||
|
@ -114,11 +125,7 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame)
|
|||
}
|
||||
Py_DECREF(f);
|
||||
}
|
||||
assert(frame->stacktop >= 0);
|
||||
for (int i = 0; i < frame->stacktop; i++) {
|
||||
Py_XDECREF(frame->localsplus[i]);
|
||||
}
|
||||
Py_XDECREF(frame->f_locals);
|
||||
_PyFrame_ClearLocals(frame);
|
||||
Py_DECREF(frame->f_funcobj);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue