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

Fix a crash on fork when using subinterpreters.
This commit is contained in:
Stéphane Wirtel 2019-02-20 15:27:22 +01:00 committed by Victor Stinner
parent 001fee14e0
commit b5409dacc4
2 changed files with 6 additions and 2 deletions

View File

@ -0,0 +1 @@
Fix a crash on fork when using subinterpreters. Contributed by Stéphane Wirtel

View File

@ -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();