summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStéphane Wirtel <stephane@wirtel.be>2019-02-20 14:27:22 (GMT)
committerVictor Stinner <vstinner@redhat.com>2019-02-20 14:27:22 (GMT)
commitb5409dacc4885146a27d06482b346e55fa12d2ec (patch)
tree61a158b3f90ebc0202d4b74093531a6527538039
parent001fee14e0f2ba5f41fb733adc69d5965925a094 (diff)
downloadcpython-b5409dacc4885146a27d06482b346e55fa12d2ec.zip
cpython-b5409dacc4885146a27d06482b346e55fa12d2ec.tar.gz
cpython-b5409dacc4885146a27d06482b346e55fa12d2ec.tar.bz2
bpo-35993: Fix _PyInterpreterState_DeleteExceptMain() (GH-11852)
Fix a crash on fork when using subinterpreters.
-rw-r--r--Misc/NEWS.d/next/Core and Builtins/2019-02-14-09-17-54.bpo-35993.Bvm3fP.rst1
-rw-r--r--Python/pystate.c7
2 files changed, 6 insertions, 2 deletions
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 0000000..3966f29
--- /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 f0b2a67..acb672b 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();