summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorVictor Stinner <vstinner@python.org>2019-11-22 09:58:00 (GMT)
committerGitHub <noreply@github.com>2019-11-22 09:58:00 (GMT)
commit310e2d25170a88ef03f6fd31efcc899fe062da2c (patch)
tree183e69c59f1997d35021f3e708c4056bb8303a05 /Python
parent91daa9d7224626dad4bb820924c01b3438ca6e3f (diff)
downloadcpython-310e2d25170a88ef03f6fd31efcc899fe062da2c.zip
cpython-310e2d25170a88ef03f6fd31efcc899fe062da2c.tar.gz
cpython-310e2d25170a88ef03f6fd31efcc899fe062da2c.tar.bz2
bpo-36854: Fix refleak in subinterpreter (GH-17331)
finalize_interp_clear() now explicitly clears the codec registry and then trigger a GC collection to clear all references.
Diffstat (limited to 'Python')
-rw-r--r--Python/pylifecycle.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c
index 7591f06..8c508e3 100644
--- a/Python/pylifecycle.c
+++ b/Python/pylifecycle.c
@@ -1210,6 +1210,14 @@ finalize_interp_clear(PyThreadState *tstate)
{
int is_main_interp = _Py_IsMainInterpreter(tstate);
+ /* bpo-36854: Explicitly clear the codec registry
+ and trigger a GC collection */
+ PyInterpreterState *interp = tstate->interp;
+ Py_CLEAR(interp->codec_search_path);
+ Py_CLEAR(interp->codec_search_cache);
+ Py_CLEAR(interp->codec_error_registry);
+ _PyGC_CollectNoFail();
+
/* Clear interpreter state and all thread states */
PyInterpreterState_Clear(tstate->interp);