diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2024-05-02 15:22:50 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-05-02 15:22:50 (GMT) |
commit | 238efbecab24204f822b1d1611914f5bcb2ae2de (patch) | |
tree | c4ea5b0a5094613a167746ed4b140d13c2f35040 /Python | |
parent | f61de0de649d31a96bacb7625d6a7b98d23b14bb (diff) | |
download | cpython-238efbecab24204f822b1d1611914f5bcb2ae2de.zip cpython-238efbecab24204f822b1d1611914f5bcb2ae2de.tar.gz cpython-238efbecab24204f822b1d1611914f5bcb2ae2de.tar.bz2 |
[3.12] gh-118272: Clear generator frame's locals when the generator is closed (#118451)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/frame.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/Python/frame.c b/Python/frame.c index b84fd9b..a49215f 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -116,6 +116,18 @@ take_ownership(PyFrameObject *f, _PyInterpreterFrame *frame) } void +_PyFrame_ClearLocals(_PyInterpreterFrame *frame) +{ + assert(frame->stacktop >= 0); + int stacktop = frame->stacktop; + frame->stacktop = 0; + for (int i = 0; i < stacktop; i++) { + Py_XDECREF(frame->localsplus[i]); + } + Py_CLEAR(frame->f_locals); +} + +void _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) { /* It is the responsibility of the owning generator/coroutine @@ -135,12 +147,8 @@ _PyFrame_ClearExceptCode(_PyInterpreterFrame *frame) } Py_DECREF(f); } - assert(frame->stacktop >= 0); - for (int i = 0; i < frame->stacktop; i++) { - Py_XDECREF(frame->localsplus[i]); - } + _PyFrame_ClearLocals(frame); Py_XDECREF(frame->frame_obj); - Py_XDECREF(frame->f_locals); Py_DECREF(frame->f_funcobj); } |