Skip to content

gh-150988: Fix OSError reference leak in oserror_init()#151219

Closed
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-150988-fix-oserror-refleak
Closed

gh-150988: Fix OSError reference leak in oserror_init()#151219
bhuvi27 wants to merge 1 commit into
python:mainfrom
bhuvi27:gh-150988-fix-oserror-refleak

Conversation

@bhuvi27

@bhuvi27 bhuvi27 commented Jun 10, 2026

Copy link
Copy Markdown

Fixes #150988

Assigning OSError fields in a subclass before super().init() stored
references in the C struct that oserror_init() later overwrote without
decref'ing, leaking one reference per field per exception.

Use Py_XSETREF when updating errno, strerror, filename, filename2, and
winerror. Add a refcount regression test in test_exceptions.py.

Use Py_XSETREF when assigning errno, strerror, filename, filename2, and
winerror so pre-existing references from subclass __init__ are released.
@bhuvi27

bhuvi27 commented Jun 10, 2026

Copy link
Copy Markdown
Author

Closing in favour of #150990 — same fix, already reviewed.

@bhuvi27 bhuvi27 closed this Jun 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reference leak in OSError when setting attributes before super().__init__

1 participant