diff options
author | Hai Shi <shihai1992@gmail.com> | 2020-08-12 21:23:30 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-12 21:23:30 (GMT) |
commit | 8ecc0c4d390d03de5cd2344aa44b69ed02ffe470 (patch) | |
tree | 0135fb23efb2c66941f278e10df29c0bd2f1cef6 /Python | |
parent | 423e77d6de497931585d1883805a9e3fa4096b0b (diff) | |
download | cpython-8ecc0c4d390d03de5cd2344aa44b69ed02ffe470.zip cpython-8ecc0c4d390d03de5cd2344aa44b69ed02ffe470.tar.gz cpython-8ecc0c4d390d03de5cd2344aa44b69ed02ffe470.tar.bz2 |
bpo-1635741: Clean sysdict and builtins of interpreter at exit (GH-21605)
Diffstat (limited to 'Python')
-rw-r--r-- | Python/pystate.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Python/pystate.c b/Python/pystate.c index d0cbf5c..f6d1956 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -294,8 +294,6 @@ PyInterpreterState_Clear(PyInterpreterState *interp) Py_CLEAR(interp->codec_error_registry); Py_CLEAR(interp->modules); Py_CLEAR(interp->modules_by_index); - Py_CLEAR(interp->sysdict); - Py_CLEAR(interp->builtins); Py_CLEAR(interp->builtins_copy); Py_CLEAR(interp->importlib); Py_CLEAR(interp->import_func); @@ -308,6 +306,14 @@ PyInterpreterState_Clear(PyInterpreterState *interp) if (_PyRuntimeState_GetFinalizing(runtime) == NULL) { _PyWarnings_Fini(interp); } + /* We don't clear sysdict and builtins until the end of this function. + Because clearing other attributes can execute arbitrary Python code + which requires sysdict and builtins. */ + PyDict_Clear(interp->sysdict); + PyDict_Clear(interp->builtins); + Py_CLEAR(interp->sysdict); + Py_CLEAR(interp->builtins); + // XXX Once we have one allocator per interpreter (i.e. // per-interpreter GC) we must ensure that all of the interpreter's // objects have been cleaned up at the point. |