Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b5409da

Browse files
matrixisevstinner
authored andcommitted
bpo-35993: Fix _PyInterpreterState_DeleteExceptMain() (GH-11852)
Fix a crash on fork when using subinterpreters.
1 parent 001fee1 commit b5409da

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix a crash on fork when using subinterpreters. Contributed by Stéphane Wirtel

Python/pystate.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,11 @@ _PyInterpreterState_DeleteExceptMain()
281281
HEAD_LOCK();
282282
PyInterpreterState *interp = _PyRuntime.interpreters.head;
283283
_PyRuntime.interpreters.head = NULL;
284-
for (; interp != NULL; interp = interp->next) {
284+
while (interp != NULL) {
285285
if (interp == _PyRuntime.interpreters.main) {
286286
_PyRuntime.interpreters.main->next = NULL;
287287
_PyRuntime.interpreters.head = interp;
288+
interp = interp->next;
288289
continue;
289290
}
290291

@@ -293,7 +294,9 @@ _PyInterpreterState_DeleteExceptMain()
293294
if (interp->id_mutex != NULL) {
294295
PyThread_free_lock(interp->id_mutex);
295296
}
296-
PyMem_RawFree(interp);
297+
PyInterpreterState *prev_interp = interp;
298+
interp = interp->next;
299+
PyMem_RawFree(prev_interp);
297300
}
298301
HEAD_UNLOCK();
299302

0 commit comments

Comments
 (0)