From b2490230ee45c001b18a735441fc3d4328e404fd Mon Sep 17 00:00:00 2001 From: Jason Haslam Date: Thu, 2 Dec 2021 22:40:05 -0700 Subject: [PATCH] bpo-45970: Fix fatal error along the failure path of Py_NewIntperter The saved thread state has to be swapped back in *before* deleting the new thread state. Otherwise, it causes a fatal error about deleting the current thread state. --- Python/pylifecycle.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index c6b2a1eb961481c..9fc2156f9732557 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1987,10 +1987,10 @@ new_interpreter(PyThreadState **tstate_p, int isolated_subinterpreter) /* Oops, it didn't work. Undo it all. */ PyErr_PrintEx(0); + PyThreadState_Swap(save_tstate); PyThreadState_Clear(tstate); PyThreadState_Delete(tstate); PyInterpreterState_Delete(interp); - PyThreadState_Swap(save_tstate); return status; }