diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-06-26-00-06-29.gh-issue-151763.pX4fYq.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-26-00-06-29.gh-issue-151763.pX4fYq.rst new file mode 100644 index 000000000000000..95bbc9562f1027a --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-06-26-00-06-29.gh-issue-151763.pX4fYq.rst @@ -0,0 +1,2 @@ +Fixed a possible crash in free-threaded builds when interpreter creation fails +due to memory allocation failure. diff --git a/Python/pystate.c b/Python/pystate.c index fed1df0173bacf1..9986fbde62affb6 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -1661,6 +1661,9 @@ new_threadstate(PyInterpreterState *interp, int whence) if (tstate == NULL) { return NULL; } + // Set the back-pointer before init_threadstate() so early cleanup can + // recognize the preallocated initial thread state after allocation failures. + tstate->base.interp = interp; #ifdef Py_GIL_DISABLED Py_ssize_t qsbr_idx = _Py_qsbr_reserve(interp);