[Python-checkins] bpo-35993: Fix _PyInterpreterState_DeleteExceptMain() (GH-11852)

Victor Stinner webhook-mailer at python.org
Wed Feb 20 09:27:26 EST 2019


https://github.com/python/cpython/commit/b5409dacc4885146a27d06482b346e55fa12d2ec
commit: b5409dacc4885146a27d06482b346e55fa12d2ec
branch: master
author: Stéphane Wirtel <stephane at wirtel.be>
committer: Victor Stinner <vstinner at redhat.com>
date: 2019-02-20T15:27:22+01:00
summary:

bpo-35993: Fix _PyInterpreterState_DeleteExceptMain() (GH-11852)

 Fix a crash on fork when using subinterpreters.

files:
A Misc/NEWS.d/next/Core and Builtins/2019-02-14-09-17-54.bpo-35993.Bvm3fP.rst
M Python/pystate.c

diff --git a/Misc/NEWS.d/next/Core and Builtins/2019-02-14-09-17-54.bpo-35993.Bvm3fP.rst b/Misc/NEWS.d/next/Core and Builtins/2019-02-14-09-17-54.bpo-35993.Bvm3fP.rst
new file mode 100644
index 000000000000..3966f292ea8e
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2019-02-14-09-17-54.bpo-35993.Bvm3fP.rst	
@@ -0,0 +1 @@
+Fix a crash on fork when using subinterpreters. Contributed by Stéphane Wirtel
diff --git a/Python/pystate.c b/Python/pystate.c
index f0b2a6729f33..acb672bdd9b8 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -281,10 +281,11 @@ _PyInterpreterState_DeleteExceptMain()
     HEAD_LOCK();
     PyInterpreterState *interp = _PyRuntime.interpreters.head;
     _PyRuntime.interpreters.head = NULL;
-    for (; interp != NULL; interp = interp->next) {
+    while (interp != NULL) {
         if (interp == _PyRuntime.interpreters.main) {
             _PyRuntime.interpreters.main->next = NULL;
             _PyRuntime.interpreters.head = interp;
+            interp = interp->next;
             continue;
         }
 
@@ -293,7 +294,9 @@ _PyInterpreterState_DeleteExceptMain()
         if (interp->id_mutex != NULL) {
             PyThread_free_lock(interp->id_mutex);
         }
-        PyMem_RawFree(interp);
+        PyInterpreterState *prev_interp = interp;
+        interp = interp->next;
+        PyMem_RawFree(prev_interp);
     }
     HEAD_UNLOCK();
 



More information about the Python-checkins mailing list