Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-109786: Fix leaks when re-enter itertools.pairwise.__next__()#109788

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Conversation

@serhiy-storchaka
Copy link
Member

@serhiy-storchakaserhiy-storchaka commentedSep 23, 2023
edited by bedevere-appbot
Loading

}
}
else {
Py_INCREF(old);
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Other simple solution is settingpo->old = NULL instead of increfingold, soold holds the only reference. It only differs from the present solution in casecheck(3, ...), and I tested much more test cases than present in this PR, including multiple re-entering points.

@rhettinger
Copy link
Contributor

How does the "borrowed reference" arise? My understanding that aniternext call returns a new reference (at least that is whatPyIter_Next() assumes.

@serhiy-storchaka
Copy link
MemberAuthor

po->old owns a reference.old holds a borrowed reference on it whenPy_TYPE(it)->tp_iternext is called.

@serhiy-storchaka
Copy link
MemberAuthor

Now the current result is preserved in all test cases.

I also found and fixed a crash due toit holding a borrowed reference. I am not sure, but thetp_iternext calls may need Py_INCREF/Py_DECREF around it.

@serhiy-storchaka
Copy link
MemberAuthor

@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).

@serhiy-storchakaserhiy-storchakaenabled auto-merge (squash)December 4, 2023 11:23
@serhiy-storchakaserhiy-storchaka merged commit6ca9d3e intopython:mainDec 4, 2023
@miss-islington-app
Copy link

Thanks@serhiy-storchaka for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11, 3.12.
🐍🍒⛏🤖

@bedevere-app
Copy link

GH-112699 is a backport of this pull request to the3.12 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestDec 4, 2023
….__next__() (pythonGH-109788)(cherry picked from commit6ca9d3e)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-appbedevere-appbot removed the needs backport to 3.12only security fixes labelDec 4, 2023
@bedevere-app
Copy link

GH-112700 is a backport of this pull request to the3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull requestDec 4, 2023
….__next__() (pythonGH-109788)(cherry picked from commit6ca9d3e)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
@bedevere-appbedevere-appbot removed the needs backport to 3.11only security fixes labelDec 4, 2023
serhiy-storchaka added a commit that referenced this pull requestDec 4, 2023
…e.__next__() (GH-109788) (GH-112699)(cherry picked from commit6ca9d3e)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
serhiy-storchaka added a commit that referenced this pull requestDec 4, 2023
…e.__next__() (GH-109788) (GH-112700)(cherry picked from commit6ca9d3e)Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
aisk pushed a commit to aisk/cpython that referenced this pull requestFeb 11, 2024
Glyphack pushed a commit to Glyphack/cpython that referenced this pull requestSep 2, 2024
@serhiy-storchakaserhiy-storchaka deleted the itertools-pairwise-reenter branchOctober 21, 2024 13:47
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@rhettingerrhettingerAwaiting requested review from rhettingerrhettinger is a code owner

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@serhiy-storchaka@rhettinger

[8]ページ先頭

©2009-2025 Movatter.jp