-
-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
gh-109786: Fix leaks when re-enter itertools.pairwise.__next__() #109788
gh-109786: Fix leaks when re-enter itertools.pairwise.__next__() #109788
Conversation
serhiy-storchaka
commented
Sep 23, 2023
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Re-entering pairwise.__next__() leaks references #109786
Modules/itertoolsmodule.c
Outdated
return NULL; | ||
} | ||
} | ||
else { | ||
Py_INCREF(old); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Other simple solution is setting po->old = NULL
instead of increfing old
, so old
holds the only reference. It only differs from the present solution in case check(3, ...)
, and I tested much more test cases than present in this PR, including multiple re-entering points.
How does the "borrowed reference" arise? My understanding that an |
|
Now the current result is preserved in all test cases. I also found and fixed a crash due to |
@rhettinger, I am going to merge this if you have no questions or objections. There are many ways to fix leaks, and I tested many variants. The proposed one is the only variant that produces the same result in all tested weird cases (but without leaking of course). |
Thanks @serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12. |
GH-112699 is a backport of this pull request to the 3.12 branch. |
….__next__() (pythonGH-109788) (cherry picked from commit 6ca9d3e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
GH-112700 is a backport of this pull request to the 3.11 branch. |
….__next__() (pythonGH-109788) (cherry picked from commit 6ca9d3e) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>