Skip to content

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

Merged
merged 2 commits into from
Apr 30, 2024

Conversation

iritkatriel
Copy link
Member

@iritkatriel iritkatriel commented Apr 25, 2024

@iritkatriel iritkatriel added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) needs backport to 3.12 only security fixes labels Apr 25, 2024
Co-authored-by: Thomas Grainger <[email protected]>
Copy link
Member

@gvanrossum gvanrossum left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, LGTM!

@iritkatriel iritkatriel merged commit 1f16b4c into python:main Apr 30, 2024
38 checks passed
@miss-islington-app
Copy link

Thanks @iritkatriel for the PR 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @iritkatriel, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 1f16b4ce569f222af74fcbb7b2ef98eee2398d20 3.12

_PyFrame_ClearLocals(_PyInterpreterFrame *frame)
{
assert(frame->stacktop >= 0);
for (int i = 0; i < frame->stacktop; i++) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think frame->stacktop = 0; needs to come before the loop to prevent the GC seeing freed objects.

Copy link
Member

@gvanrossum gvanrossum May 1, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me make a fix for that. NM, approved gh-118478 instead.

SonicField pushed a commit to SonicField/cpython that referenced this pull request May 8, 2024
@hugovk hugovk removed the needs backport to 3.12 only security fixes label Feb 26, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Generator .close does not release resources
5 participants