-
-
Notifications
You must be signed in to change notification settings - Fork 32.1k
gh-118272: Clear generator frame's locals when the generator is closed #118277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Fix bug where ``generator.close`` does not free the generator frame's | ||
locals. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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++) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
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); | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.