diff options
author | Stéphane Wirtel <stephane@wirtel.be> | 2019-02-20 14:27:22 (GMT) |
---|---|---|
committer | Victor Stinner <vstinner@redhat.com> | 2019-02-20 14:27:22 (GMT) |
commit | b5409dacc4885146a27d06482b346e55fa12d2ec (patch) | |
tree | 61a158b3f90ebc0202d4b74093531a6527538039 /Python/pystate.c | |
parent | 001fee14e0f2ba5f41fb733adc69d5965925a094 (diff) | |
download | cpython-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.
Diffstat (limited to 'Python/pystate.c')
-rw-r--r-- | Python/pystate.c | 7 |
1 files changed, 5 insertions, 2 deletions
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(); |