You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#0 tstate_delete_common.constprop.0 (tstate=tstate@entry=0x555555666ca0, release_gil=0) at ../Python/pystate.c:1854
#1 0x00007ffff78cd341 in zapthreads (interp=0x7ffff74c8010) at ../Python/pystate.c:1915
#2 PyInterpreterState_Delete (interp=0x7ffff74c8010) at ../Python/pystate.c:1016
#3 0x00005555555552ef in main () at repro.c:16
(note the address passed to tstate_delete_common is definitely corrupt, and not the address of any PyThreadState created in this program)
This was triggered by creating a new PyThreeadState for the interpreter, switching to it, deleting an old thread state for the same interpreter, and then calling Py_EndInterpreter (on the new thread state).
If it matters, the reason I am doing it this way is that in 3.12 you can't actually delete (via PyThreadState_Delete) the first PyThreadState of the interpreter ... it looks to me like it never gets zero'd out (because it is the one that has storage inside the interpreterstate) so it causes an abort when it is subsequently reallocated. :( So you have to leave that one allocated. This is fixed in 3.13+
Activity
ZeroIntensity commentedon May 17, 2025
@ericsnowcurrently This is the
zapthreadsproblem that I was talking about yesterday.I'm pretty sure #128640 will fix this.
b-pass commentedon May 17, 2025
I updated the example code to a complete compilable description, this crashes for me. Using deadsnakes repo on ubuntu 24.04, which is 3.14.b1.
ZeroIntensity commentedon May 17, 2025
Huh, that repro looks wrong.
PyThreadState_Deletecannot be called with a thread state that is attached.b-pass commentedon May 17, 2025
Does the PyThreadState_Swap not detach it?
ZeroIntensity commentedon May 17, 2025
Oh wait, I see that you delete
orig, nottemp.b-pass commentedon May 18, 2025
If it matters, the reason I am doing it this way is that in 3.12 you can't actually delete (via PyThreadState_Delete) the first PyThreadState of the interpreter ... it looks to me like it never gets zero'd out (because it is the one that has storage inside the interpreterstate) so it causes an abort when it is subsequently reallocated. :( So you have to leave that one allocated. This is fixed in 3.13+
gh-134144: Fix use-after-free in zapthreads() (#134145)
pythongh-134144: Fix use-after-free in zapthreads() (pythonGH-134145)
[3.14] gh-134144: Fix use-after-free in zapthreads() (GH-134145) (#13…
pythongh-134144: Fix use-after-free in zapthreads() (python#134145)
pythongh-134144: Fix use-after-free in zapthreads() (python#134145)