Skip to content

Commit a8bc036

Browse files
pythongh-123504: Fix reference leak in finalization of _tkinter (python#123505)
1 parent cfbc841 commit a8bc036

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fixed reference leak in the finalization of :mod:`tkinter`.

Modules/_tkinter.c

+19-8
Original file line numberDiff line numberDiff line change
@@ -3389,17 +3389,28 @@ DisableEventHook(void)
33893389
#endif
33903390
}
33913391

3392+
static int
3393+
module_clear(PyObject *mod)
3394+
{
3395+
Py_CLEAR(Tkinter_TclError);
3396+
Py_CLEAR(Tkapp_Type);
3397+
Py_CLEAR(Tktt_Type);
3398+
Py_CLEAR(PyTclObject_Type);
3399+
return 0;
3400+
}
3401+
3402+
static void
3403+
module_free(void *mod)
3404+
{
3405+
module_clear((PyObject *)mod);
3406+
}
33923407

33933408
static struct PyModuleDef _tkintermodule = {
33943409
PyModuleDef_HEAD_INIT,
3395-
"_tkinter",
3396-
NULL,
3397-
-1,
3398-
moduleMethods,
3399-
NULL,
3400-
NULL,
3401-
NULL,
3402-
NULL
3410+
.m_name = "_tkinter",
3411+
.m_methods = moduleMethods,
3412+
.m_clear = module_clear,
3413+
.m_free = module_free
34033414
};
34043415

34053416
PyMODINIT_FUNC

0 commit comments

Comments
 (0)