Skip to content

Comments

gh-144986: Fix memory leak in atexit.register()#144987

Merged
pablogsal merged 8 commits intopython:mainfrom
ashm-dev:gh-144986-fix-atexit-memleak
Feb 19, 2026
Merged

gh-144986: Fix memory leak in atexit.register()#144987
pablogsal merged 8 commits intopython:mainfrom
ashm-dev:gh-144986-fix-atexit-memleak

Conversation

@ashm-dev
Copy link
Contributor

@ashm-dev ashm-dev commented Feb 19, 2026

PyTuple_GetSlice() in atexit_register() returns a new reference that was never decref'd, leaking a tuple on every atexit.register() call.

Also added a missing NULL check after PyTuple_GetSlice().

@ashm-dev ashm-dev force-pushed the gh-144986-fix-atexit-memleak branch from 9e66555 to 0e0abc3 Compare February 19, 2026 09:19
Copy link
Contributor

@sergey-miryanov sergey-miryanov left a comment

Choose a reason for hiding this comment

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

LGTM

@pablogsal
Copy link
Member

Thanks for the fix @ashm-dev !

@pablogsal
Copy link
Member

Does this affect 3.13?

@pablogsal pablogsal merged commit 50c1471 into python:main Feb 19, 2026
51 checks passed
@miss-islington-app
Copy link

Thanks @ashm-dev for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Feb 19, 2026
(cherry picked from commit 50c1471)

Co-authored-by: Shamil <ashm.tech@proton.me>
@bedevere-app
Copy link

bedevere-app bot commented Feb 19, 2026

GH-145020 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 Feb 19, 2026
@sergey-miryanov
Copy link
Contributor

Does this affect 3.13?

@pablogsal No, it is not. Method was rewritten in 3.14 (3b76682).

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