gh-123504: Fix reference leak in finalization of `_tkinter` (#123505)

This commit is contained in:
Peter Bierma 2024-09-03 16:35:57 -04:00 committed by GitHub
parent cfbc841ef3
commit a8bc03696c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 8 deletions

View File

@ -0,0 +1 @@
Fixed reference leak in the finalization of :mod:`tkinter`.

View File

@ -3389,17 +3389,28 @@ DisableEventHook(void)
#endif #endif
} }
static int
module_clear(PyObject *mod)
{
Py_CLEAR(Tkinter_TclError);
Py_CLEAR(Tkapp_Type);
Py_CLEAR(Tktt_Type);
Py_CLEAR(PyTclObject_Type);
return 0;
}
static void
module_free(void *mod)
{
module_clear((PyObject *)mod);
}
static struct PyModuleDef _tkintermodule = { static struct PyModuleDef _tkintermodule = {
PyModuleDef_HEAD_INIT, PyModuleDef_HEAD_INIT,
"_tkinter", .m_name = "_tkinter",
NULL, .m_methods = moduleMethods,
-1, .m_clear = module_clear,
moduleMethods, .m_free = module_free
NULL,
NULL,
NULL,
NULL
}; };
PyMODINIT_FUNC PyMODINIT_FUNC