From 3ce82f55454e97ce6d3d426da40b54f9cfaacaf4 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 12:08:59 +0100 Subject: [PATCH 1/2] bpo-36333, bpo-36356: Fix _PyEval_FiniThreads() _PyEval_FiniThreads() now free the pending lock. --- Python/ceval.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/Python/ceval.c b/Python/ceval.c index d6a0b335955e098..f06a9f02666a36c 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -169,8 +169,10 @@ PyEval_ThreadsInitialized(void) void PyEval_InitThreads(void) { - if (gil_created()) + if (gil_created()) { return; + } + PyThread_init_thread(); create_gil(); take_gil(_PyThreadState_GET()); @@ -184,10 +186,17 @@ PyEval_InitThreads(void) void _PyEval_FiniThreads(void) { - if (!gil_created()) + if (!gil_created()) { return; + } + destroy_gil(); assert(!gil_created()); + + if (_PyRuntime.ceval.pending.lock == NULL) { + PyThread_free_lock(_PyRuntime.ceval.pending.lock); + _PyRuntime.ceval.pending.lock = NULL; + } } void From 09f6fa9b513d1fd3e90abeeec05bef1fdd067240 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 19 Mar 2019 13:54:02 +0100 Subject: [PATCH 2/2] fix test --- Python/ceval.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Python/ceval.c b/Python/ceval.c index f06a9f02666a36c..40320bf35703048 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -193,7 +193,7 @@ _PyEval_FiniThreads(void) destroy_gil(); assert(!gil_created()); - if (_PyRuntime.ceval.pending.lock == NULL) { + if (_PyRuntime.ceval.pending.lock != NULL) { PyThread_free_lock(_PyRuntime.ceval.pending.lock); _PyRuntime.ceval.pending.lock = NULL; }