Bug report
Bug description:
On allocation failure, interp == NULL and that confuses free_threadstate(). Possible fix is to set interp inside alloc_threadstate().
Reproducer, insert after the alloc_threadstate() call:
_PyThreadStateImpl *tstate = alloc_threadstate(interp); if (tstate == NULL) { return NULL; } if (getenv("PY_TSTATE_FAIL_INJECT")) { fprintf(stderr, "INJECT: tstate=%p interp=%p base.interp=%p\n", (void *)tstate, (void *)interp, (void *)tstate->base.interp); free_threadstate(tstate); return NULL; }
CPython versions tested on:
CPython main branch
Operating systems tested on:
Linux