Skip to content

gh-150988: Fix refleak in OSError when attrs are set before super().__init__#150990

Merged
vstinner merged 8 commits into
python:mainfrom
lgeiger:refleak-oserror
Jun 10, 2026
Merged

gh-150988: Fix refleak in OSError when attrs are set before super().__init__#150990
vstinner merged 8 commits into
python:mainfrom
lgeiger:refleak-oserror

Conversation

@lgeiger

@lgeiger lgeiger commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

This PR uses Py_XSETREF instead of raw assignments inside oserror_init to prevent reference leaks when assigning attributed before oserror_init is called.

@sobolevn sobolevn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

(not a full review, just comments about tests)

Comment thread Lib/test/test_exceptions.py Outdated
Comment thread Lib/test/test_exceptions.py Outdated
Comment thread Lib/test/test_exceptions.py Outdated
Comment thread Lib/test/test_exceptions.py
Comment thread Lib/test/test_exceptions.py Outdated
@lgeiger

lgeiger commented Jun 8, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for the fast review, I wasn't aware of -R. I updated the unittests in a11a244 to use the builtin ref leak checker and verified that ./python.exe -m test -R 3:3 test_exceptions -m test_oserror_reinit_leak fails on main but passes on this PR.

Comment thread Lib/test/test_exceptions.py Outdated
Comment thread Misc/NEWS.d/next/Core_and_Builtins/2026-06-05-22-52-41.gh-issue-150988.fDKfMJ.rst Outdated
Co-authored-by: Victor Stinner <vstinner@python.org>
@lgeiger lgeiger requested a review from vstinner June 8, 2026 15:46
@bhuvi27

bhuvi27 commented Jun 10, 2026

Copy link
Copy Markdown

Looks good — same Py_XSETREF approach I explored independently in #151219. Closing mine.

Comment thread Lib/test/test_exceptions.py
Comment thread Lib/test/test_exceptions.py Outdated
@vstinner vstinner added needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Jun 10, 2026
@vstinner vstinner enabled auto-merge (squash) June 10, 2026 12:04

@vstinner vstinner left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

@vstinner vstinner merged commit f2a0f82 into python:main Jun 10, 2026
64 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @lgeiger for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14, 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

GH-151240 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Jun 10, 2026
@bedevere-app

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

GH-151241 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Jun 10, 2026
@bedevere-app

bedevere-app Bot commented Jun 10, 2026

Copy link
Copy Markdown

GH-151242 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.13 bugs and security fixes label Jun 10, 2026
@vstinner

Copy link
Copy Markdown
Member

Merged, thanks for the fix.

vstinner added a commit that referenced this pull request Jun 10, 2026
…`super().__init__()` (GH-150990) (#151242)

gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Jun 10, 2026
…`super().__init__()` (GH-150990) (#151241)

gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
vstinner added a commit that referenced this pull request Jun 10, 2026
…`super().__init__()` (GH-150990) (#151240)

gh-150988: Fix refleak in `OSError` when attrs are set before `super().__init__()` (GH-150990)
(cherry picked from commit f2a0f82)

Co-authored-by: Lukas Geiger <lukas.geiger94@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
@lgeiger

lgeiger commented Jun 10, 2026

Copy link
Copy Markdown
Contributor Author

Great! Thanks for the quick review!

@lgeiger lgeiger deleted the refleak-oserror branch June 10, 2026 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants