Skip to content

Commit 283ab0e

Browse files
authored
GH-99205: Mark new interpreters and threads as non-static (GH-99268)
1 parent 58ee5d8 commit 283ab0e

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix an issue that prevented :c:type:`PyThreadState` and
2+
:c:type:`PyInterpreterState` memory from being freed properly.

Python/pystate.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ PyInterpreterState_New(void)
356356
interp = &runtime->_main_interpreter;
357357
assert(interp->id == 0);
358358
assert(interp->next == NULL);
359+
assert(interp->_static);
359360

360361
interpreters->main = interp;
361362
}
@@ -370,6 +371,9 @@ PyInterpreterState_New(void)
370371
// Set to _PyInterpreterState_INIT.
371372
memcpy(interp, &initial._main_interpreter,
372373
sizeof(*interp));
374+
// We need to adjust any fields that are different from the initial
375+
// interpreter (as defined in _PyInterpreterState_INIT):
376+
interp->_static = false;
373377

374378
if (id < 0) {
375379
/* overflow or Py_Initialize() not called yet! */
@@ -837,6 +841,7 @@ new_threadstate(PyInterpreterState *interp)
837841
assert(id == 1);
838842
used_newtstate = 0;
839843
tstate = &interp->_initial_thread;
844+
assert(tstate->_static);
840845
}
841846
else {
842847
// Every valid interpreter must have at least one thread.
@@ -848,6 +853,9 @@ new_threadstate(PyInterpreterState *interp)
848853
memcpy(tstate,
849854
&initial._main_interpreter._initial_thread,
850855
sizeof(*tstate));
856+
// We need to adjust any fields that are different from the initial
857+
// thread (as defined in _PyThreadState_INIT):
858+
tstate->_static = false;
851859
}
852860
interp->threads.head = tstate;
853861

0 commit comments

Comments
 (0)