Skip to content

Commit ddad17e

Browse files
committed
Delay deletion of stack chunks until thread state is deleted.
1 parent 236beca commit ddad17e

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

Python/pystate.c

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -292,9 +292,7 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
292292

293293
HEAD_LOCK(runtime);
294294
for (PyThreadState *p = interp->tstate_head; p != NULL; p = p->next) {
295-
if (p != tstate) {
296-
PyThreadState_Clear(p);
297-
}
295+
PyThreadState_Clear(p);
298296
}
299297
HEAD_UNLOCK(runtime);
300298

@@ -326,7 +324,6 @@ interpreter_clear(PyInterpreterState *interp, PyThreadState *tstate)
326324

327325
/* Last garbage collection on this interpreter */
328326
_PyGC_CollectNoFail(tstate);
329-
PyThreadState_Clear(tstate);
330327
_PyGC_Fini(interp);
331328

332329
/* We don't clear sysdict and builtins until the end of this function.
@@ -900,13 +897,6 @@ PyThreadState_Clear(PyThreadState *tstate)
900897
if (tstate->on_delete != NULL) {
901898
tstate->on_delete(tstate->on_delete_data);
902899
}
903-
_PyStackChunk *chunk = tstate->datastack_chunk;
904-
tstate->datastack_chunk = NULL;
905-
while (chunk != NULL) {
906-
_PyStackChunk *prev = chunk->previous;
907-
_PyObject_VirtualFree(chunk, chunk->size);
908-
chunk = prev;
909-
}
910900
}
911901

912902

@@ -939,6 +929,13 @@ tstate_delete_common(PyThreadState *tstate,
939929
{
940930
PyThread_tss_set(&gilstate->autoTSSkey, NULL);
941931
}
932+
_PyStackChunk *chunk = tstate->datastack_chunk;
933+
tstate->datastack_chunk = NULL;
934+
while (chunk != NULL) {
935+
_PyStackChunk *prev = chunk->previous;
936+
_PyObject_VirtualFree(chunk, chunk->size);
937+
chunk = prev;
938+
}
942939
}
943940

944941
static void

0 commit comments

Comments
 (0)