summaryrefslogtreecommitdiffstats
path: root/Python/pylifecycle.c
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2020-11-03 17:07:15 (GMT)
committerGitHub <noreply@github.com>2020-11-03 17:07:15 (GMT)
commitfd957c124c44441d9c5eaf61f7af8cf266bafcb1 (patch)
tree2d73071bb42fe4496d11d79007eb4930fe5fd673 /Python/pylifecycle.c
parent212d32f45c91849c17a82750df1ac498d63976be (diff)
downloadcpython-fd957c124c44441d9c5eaf61f7af8cf266bafcb1.zip
cpython-fd957c124c44441d9c5eaf61f7af8cf266bafcb1.tar.gz
cpython-fd957c124c44441d9c5eaf61f7af8cf266bafcb1.tar.bz2
bpo-41796: Call _PyAST_Fini() earlier to fix a leak (GH-23131)
Call _PyAST_Fini() on all interpreters, not only on the main interpreter. Also, call it ealier to fix a reference leak. Python types contain a reference to themselves in in their PyTypeObject.tp_mro member. _PyAST_Fini() must called before the last GC collection to destroy AST types. _PyInterpreterState_Clear() now calls _PyAST_Fini(). It now also calls _PyWarnings_Fini() on subinterpeters, not only on the main interpreter. Add an assertion in AST init_types() to ensure that the _ast module is no longer used after _PyAST_Fini() has been called.
Diffstat (limited to 'Python/pylifecycle.c')
-rw-r--r--Python/pylifecycle.c8
1 files changed, 0 insertions, 8 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index ff58c1b..cad0fa7 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1545,12 +1545,6 @@ flush_std_files(void)
static void
finalize_interp_types(PyThreadState *tstate)
{
- // The _ast module state is shared by all interpreters.
- // The state must only be cleared by the main interpreter.
- if (_Py_IsMainInterpreter(tstate)) {
- _PyAST_Fini(tstate);
- }
-
_PyExc_Fini(tstate);
_PyFrame_Fini(tstate);
_PyAsyncGen_Fini(tstate);
@@ -1591,8 +1585,6 @@ finalize_interp_clear(PyThreadState *tstate)
_Py_ClearFileSystemEncoding();
}
- _PyWarnings_Fini(tstate->interp);
-
finalize_interp_types(tstate);
}