]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-98608: Fix Failure-handling in new_interpreter() (gh-102658)
authorEric Snow <ericsnowcurrently@gmail.com>
Tue, 21 Mar 2023 18:47:55 +0000 (12:47 -0600)
committerGitHub <noreply@github.com>
Tue, 21 Mar 2023 18:47:55 +0000 (12:47 -0600)
The error-handling code in new_interpreter() has been broken for a while.  We hadn't noticed because those code mostly doesn't fail.  (I noticed while working on gh-101660.)  The problem is that we try to clear/delete the newly-created thread/interpreter using itself, which just failed.  The solution is to switch back to the calling thread state first.

https://github.com/python/cpython/issues/98608

Python/pylifecycle.c

index 0d546d52087e10657ecb8aa9ee48bb5903578e0c..d0e85519d23464e8e7ce8e4654dbf2dcccfa59e5 100644 (file)
@@ -2062,10 +2062,10 @@ error:
 
     /* 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;
 }