mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
gh-112723: Call PyThreadState_Clear()
from the correct interpreter (#112776)
The `PyThreadState_Clear()` function must only be called with the GIL held and must be called from the same interpreter as the passed in thread state. Otherwise, any Python objects on the thread state may be destroyed using the wrong interpreter, leading to memory corruption. This is also important for `Py_GIL_DISABLED` builds because free lists will be associated with PyThreadStates and cleared in `PyThreadState_Clear()`. This fixes two places that called `PyThreadState_Clear()` from the wrong interpreter and adds an assertion to `PyThreadState_Clear()`.
This commit is contained in:
parent
8a4c1f3ff1
commit
a3c031884d
6 changed files with 34 additions and 55 deletions
|
@ -124,7 +124,7 @@ _PyEval_Vector(PyThreadState *tstate,
|
|||
PyObject *kwnames);
|
||||
|
||||
extern int _PyEval_ThreadsInitialized(void);
|
||||
extern PyStatus _PyEval_InitGIL(PyThreadState *tstate, int own_gil);
|
||||
extern void _PyEval_InitGIL(PyThreadState *tstate, int own_gil);
|
||||
extern void _PyEval_FiniGIL(PyInterpreterState *interp);
|
||||
|
||||
extern void _PyEval_AcquireLock(PyThreadState *tstate);
|
||||
|
|
|
@ -63,7 +63,7 @@ extern void _PyArg_Fini(void);
|
|||
extern void _Py_FinalizeAllocatedBlocks(_PyRuntimeState *);
|
||||
|
||||
extern PyStatus _PyGILState_Init(PyInterpreterState *interp);
|
||||
extern PyStatus _PyGILState_SetTstate(PyThreadState *tstate);
|
||||
extern void _PyGILState_SetTstate(PyThreadState *tstate);
|
||||
extern void _PyGILState_Fini(PyInterpreterState *interp);
|
||||
|
||||
extern void _PyGC_DumpShutdownStats(PyInterpreterState *interp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue