bpo-42745: finalize_interp_types() calls _PyType_Fini() (GH-23953)

Call _PyType_Fini() in subinterpreters.

Fix reference leaks in subinterpreters.
This commit is contained in:
Victor Stinner 2020-12-26 20:26:08 +01:00 committed by GitHub
parent 3bcc4ead3f
commit f4507231e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 8 deletions

View File

@ -286,7 +286,9 @@ void
_PyType_Fini(PyThreadState *tstate) _PyType_Fini(PyThreadState *tstate)
{ {
_PyType_ClearCache(&tstate->interp->type_cache); _PyType_ClearCache(&tstate->interp->type_cache);
if (_Py_IsMainInterpreter(tstate)) {
clear_slotdefs(); clear_slotdefs();
}
} }

View File

@ -2359,10 +2359,9 @@ _PyUnicode_FromId(_Py_Identifier *id)
static void static void
unicode_clear_identifiers(PyThreadState *tstate) unicode_clear_identifiers(struct _Py_unicode_state *state)
{ {
PyInterpreterState *interp = _PyInterpreterState_GET(); struct _Py_unicode_ids *ids = &state->ids;
struct _Py_unicode_ids *ids = &interp->unicode.ids;
for (Py_ssize_t i=0; i < ids->size; i++) { for (Py_ssize_t i=0; i < ids->size; i++) {
Py_XDECREF(ids->array[i]); Py_XDECREF(ids->array[i]);
} }
@ -16243,7 +16242,7 @@ _PyUnicode_Fini(PyThreadState *tstate)
_PyUnicode_FiniEncodings(&state->fs_codec); _PyUnicode_FiniEncodings(&state->fs_codec);
unicode_clear_identifiers(tstate); unicode_clear_identifiers(state);
for (Py_ssize_t i = 0; i < 256; i++) { for (Py_ssize_t i = 0; i < 256; i++) {
Py_CLEAR(state->latin1[i]); Py_CLEAR(state->latin1[i]);

View File

@ -1573,6 +1573,7 @@ finalize_interp_types(PyThreadState *tstate)
_PyFrame_Fini(tstate); _PyFrame_Fini(tstate);
_PyAsyncGen_Fini(tstate); _PyAsyncGen_Fini(tstate);
_PyContext_Fini(tstate); _PyContext_Fini(tstate);
_PyType_Fini(tstate);
// Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses // Call _PyUnicode_ClearInterned() before _PyDict_Fini() since it uses
// a dict internally. // a dict internally.
_PyUnicode_ClearInterned(tstate); _PyUnicode_ClearInterned(tstate);
@ -1751,9 +1752,6 @@ Py_FinalizeEx(void)
/* Destroy the database used by _PyImport_{Fixup,Find}Extension */ /* Destroy the database used by _PyImport_{Fixup,Find}Extension */
_PyImport_Fini(); _PyImport_Fini();
/* Cleanup typeobject.c's internal caches. */
_PyType_Fini(tstate);
/* unload faulthandler module */ /* unload faulthandler module */
_PyFaulthandler_Fini(); _PyFaulthandler_Fini();