diff options
author | Victor Stinner <vstinner@python.org> | 2020-03-18 02:04:33 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-03-18 02:04:33 (GMT) |
commit | 29356e03d4f8800b04f799efe7a10e3ce8b16f61 (patch) | |
tree | aab7efc54ee7ee204ca32aa73ec9c2134c0a41f3 /Python/ceval_gil.h | |
parent | 23ef89db7ae46d160650263cc80479c2ed6693fb (diff) | |
download | cpython-29356e03d4f8800b04f799efe7a10e3ce8b16f61.zip cpython-29356e03d4f8800b04f799efe7a10e3ce8b16f61.tar.gz cpython-29356e03d4f8800b04f799efe7a10e3ce8b16f61.tar.bz2 |
bpo-39877: Fix take_gil() for daemon threads (GH-19054)
bpo-39877, bpo-39984: If the thread must exit, don't access tstate to
prevent a potential crash: tstate memory has been freed.
Diffstat (limited to 'Python/ceval_gil.h')
-rw-r--r-- | Python/ceval_gil.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Python/ceval_gil.h b/Python/ceval_gil.h index 9c051ae..f8b06ac 100644 --- a/Python/ceval_gil.h +++ b/Python/ceval_gil.h @@ -281,13 +281,17 @@ _ready: if (_Py_atomic_load_relaxed(&ceval->gil_drop_request)) { RESET_GIL_DROP_REQUEST(ceval); } - if (tstate->async_exc != NULL) { + + int must_exit = tstate_must_exit(tstate); + + /* Don't access tstate if the thread must exit */ + if (!must_exit && tstate->async_exc != NULL) { _PyEval_SignalAsyncExc(ceval); } MUTEX_UNLOCK(gil->mutex); - if (tstate_must_exit(tstate)) { + if (must_exit) { /* bpo-36475: If Py_Finalize() has been called and tstate is not the thread which called Py_Finalize(), exit immediately the thread. |