diff options
author | Victor Stinner <vstinner@python.org> | 2020-12-26 19:26:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-26 19:26:08 (GMT) |
commit | f4507231e3f0cf8827cec5592571ce371c6813e8 (patch) | |
tree | 1945e1cd6088d46c00f68f8a4a89eb35154ddf6c | |
parent | 3bcc4ead3f66a58604b7ce87d14e909406c3b364 (diff) | |
download | cpython-f4507231e3f0cf8827cec5592571ce371c6813e8.zip cpython-f4507231e3f0cf8827cec5592571ce371c6813e8.tar.gz cpython-f4507231e3f0cf8827cec5592571ce371c6813e8.tar.bz2 |
bpo-42745: finalize_interp_types() calls _PyType_Fini() (GH-23953)
Call _PyType_Fini() in subinterpreters.
Fix reference leaks in subinterpreters.
-rw-r--r-- | Objects/typeobject.c | 4 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 7 | ||||
-rw-r--r-- | Python/pylifecycle.c | 4 |
3 files changed, 7 insertions, 8 deletions
diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 43c499a..3498f0d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -286,7 +286,9 @@ void _PyType_Fini(PyThreadState *tstate) { _PyType_ClearCache(&tstate->interp->type_cache); - clear_slotdefs(); + if (_Py_IsMainInterpreter(tstate)) { + clear_slotdefs(); + } } diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index a03ca9a..ad32a06 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -2359,10 +2359,9 @@ _PyUnicode_FromId(_Py_Identifier *id) static void -unicode_clear_identifiers(PyThreadState *tstate) +unicode_clear_identifiers(struct _Py_unicode_state *state) { - PyInterpreterState *interp = _PyInterpreterState_GET(); - struct _Py_unicode_ids *ids = &interp->unicode.ids; + struct _Py_unicode_ids *ids = &state->ids; for (Py_ssize_t i=0; i < ids->size; i++) { Py_XDECREF(ids->array[i]); } @@ -16243,7 +16242,7 @@ _PyUnicode_Fini(PyThreadState *tstate) _PyUnicode_FiniEncodings(&state->fs_codec); - unicode_clear_identifiers(tstate); + unicode_clear_identifiers(state); for (Py_ssize_t i = 0; i < 256; i++) { Py_CLEAR(state->latin1[i]); diff --git a/Python/pylifecycle.c b/Python/pylifecycle.c index ccbacb4..9828dff 100644 --- a/Python/pylifecycle.c +++ b/Python/pylifecycle.c @@ -1573,6 +1573,7 @@ finalize_interp_types(PyThreadState *tstate) _PyFrame_Fini(tstate); _PyAsyncGen_Fini(tstate); _PyContext_Fini(tstate); + _PyType_Fini(tstate); // Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses // a dict internally. _PyUnicode_ClearInterned(tstate); @@ -1751,9 +1752,6 @@ Py_FinalizeEx(void) /* Destroy the database used by _PyImport_{Fixup,Find}Extension */ _PyImport_Fini(); - /* Cleanup typeobject.c's internal caches. */ - _PyType_Fini(tstate); - /* unload faulthandler module */ _PyFaulthandler_Fini(); |