diff options
| author | Sam Gross <colesbury@gmail.com> | 2023-12-13 00:20:21 (GMT) |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-12-13 00:20:21 (GMT) |
| commit | a3c031884d2f16d84aacc3f733c047b3a6cae208 (patch) | |
| tree | db560340456c0b7ec034e3c03382ca3d077b9628 /Python/ceval_gil.c | |
| parent | 8a4c1f3ff1e3d7ed2e00e77b94056f9bb7f9ae3b (diff) | |
| download | cpython-a3c031884d2f16d84aacc3f733c047b3a6cae208.zip cpython-a3c031884d2f16d84aacc3f733c047b3a6cae208.tar.gz cpython-a3c031884d2f16d84aacc3f733c047b3a6cae208.tar.bz2 | |
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()`.
Diffstat (limited to 'Python/ceval_gil.c')
| -rw-r--r-- | Python/ceval_gil.c | 4 |
1 files changed, 1 insertions, 3 deletions
diff --git a/Python/ceval_gil.c b/Python/ceval_gil.c index 7581daa..d70abbc 100644 --- a/Python/ceval_gil.c +++ b/Python/ceval_gil.c @@ -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 |
