Skip to content

gh-155363: Fix QSBR slot leak on thread state creation failure - #155365

Merged
nascheme merged 3 commits into
python:mainfrom
nascheme:gh-155363-fix-qsbr-reserve-leak
Aug 11, 2026
Merged

gh-155363: Fix QSBR slot leak on thread state creation failure#155365
nascheme merged 3 commits into
python:mainfrom
nascheme:gh-155363-fix-qsbr-reserve-leak

Conversation

@nascheme

@nascheme nascheme commented Aug 7, 2026

Copy link
Copy Markdown
Member

In the free-threaded build, new_threadstate() reserves a QSBR thread-state slot before it can still fail for other reasons, but the failure paths only called free_threadstate(), which does not know about the reservation.

Add _Py_qsbr_unreserve() which returns the unregistered entry to the freelist.

In the free-threaded build, new_threadstate() reserves a QSBR thread-state
slot before it can still fail for other reasons, but the failure paths only
called free_threadstate(), which does not know about the reservation.
@nascheme nascheme added performance Performance or resource usage topic-free-threading needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Aug 7, 2026
@nascheme
nascheme marked this pull request as ready for review August 7, 2026 21:29
Comment thread Python/pystate.c
By moving the call before the _Py_qsbr_reserve, we don't need the
_Py_qsbr_unreserve helper and code is a bit simpler.
@nascheme
nascheme requested a review from markshannon as a code owner August 10, 2026 18:12
@nascheme
nascheme merged commit 44e92d4 into python:main Aug 11, 2026
58 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @nascheme for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Aug 11, 2026

Copy link
Copy Markdown

GH-155579 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 Aug 11, 2026
mbeijen pushed a commit to mbeijen/cpython that referenced this pull request Aug 14, 2026
…ythongh-155365)

In the free-threaded build, new_threadstate() reserves a QSBR thread-state
slot before it can still fail for other reasons, but the failure paths only
called free_threadstate(), which does not know about the reservation.
Restructure code so failure path doesn't leak.
hugovk pushed a commit that referenced this pull request Aug 22, 2026
…gh-155365) (#155579)

Co-authored-by: Neil Schemenauer <nas-github@arctrix.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance or resource usage topic-free-threading

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants