mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +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
|
@ -447,7 +447,7 @@ init_own_gil(PyInterpreterState *interp, struct _gil_runtime_state *gil)
|
|||
interp->ceval.own_gil = 1;
|
||||
}
|
||||
|
||||
PyStatus
|
||||
void
|
||||
_PyEval_InitGIL(PyThreadState *tstate, int own_gil)
|
||||
{
|
||||
assert(tstate->interp->ceval.gil == NULL);
|
||||
|
@ -466,8 +466,6 @@ _PyEval_InitGIL(PyThreadState *tstate, int own_gil)
|
|||
|
||||
// Lock the GIL and mark the current thread as attached.
|
||||
_PyThreadState_Attach(tstate);
|
||||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue