Skip to content

Commit c732ecc

Browse files
committed
gh-99377: Prevent raising audit event when thread state has not actually been set.
This can occur during initialization. Without the check, later calls to get the interpreter state will cause a fatal error.
1 parent 51d1035 commit c732ecc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

Python/pystate.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,9 @@ PyThreadState_New(PyInterpreterState *interp)
875875
PyThreadState *tstate = new_threadstate(interp);
876876
if (tstate) {
877877
_PyThreadState_SetCurrent(tstate);
878-
if (PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0) {
878+
if (_PyThreadState_GET()
879+
&& PySys_Audit("cpython.PyThreadState_New", "K", tstate->id) < 0
880+
) {
879881
PyThreadState_Clear(tstate);
880882
_PyThreadState_DeleteCurrent(tstate);
881883
return NULL;

0 commit comments

Comments
 (0)