diff options
author | Irit Katriel <1055913+iritkatriel@users.noreply.github.com> | 2024-04-30 18:32:25 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-30 18:32:25 (GMT) |
commit | 1f16b4ce569f222af74fcbb7b2ef98eee2398d20 (patch) | |
tree | 7622e1756c99f6028b41585131a317948762f221 /Python | |
parent | f7747f73a9d9b9b1661c1a69cd8d934d56bbd3b3 (diff) | |
download | cpython-1f16b4ce569f222af74fcbb7b2ef98eee2398d20.zip cpython-1f16b4ce569f222af74fcbb7b2ef98eee2398d20.tar.gz cpython-1f16b4ce569f222af74fcbb7b2ef98eee2398d20.tar.bz2 |
gh-118272: Clear generator frame's locals when the generator is closed (#118277)
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
Diffstat (limited to 'Python')
-rw-r--r-- | Python/frame.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/Python/frame.c b/Python/frame.c index db9d133..ec390e7 100644 --- a/Python/frame.c +++ b/Python/frame.c @@ -95,6 +95,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) { /* It is the responsibility of the owning generator/coroutine @@ -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); } |