]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-123504: Fix reference leak in finalization of `_tkinter` (#123505)
authorPeter Bierma <zintensitydev@gmail.com>
Tue, 3 Sep 2024 20:35:57 +0000 (16:35 -0400)
committerGitHub <noreply@github.com>
Tue, 3 Sep 2024 20:35:57 +0000 (20:35 +0000)
Misc/NEWS.d/next/Library/2024-08-30-09-01-35.gh-issue-123504.lJ9_BB.rst [new file with mode: 0644]
Modules/_tkinter.c

diff --git a/Misc/NEWS.d/next/Library/2024-08-30-09-01-35.gh-issue-123504.lJ9_BB.rst b/Misc/NEWS.d/next/Library/2024-08-30-09-01-35.gh-issue-123504.lJ9_BB.rst
new file mode 100644 (file)
index 0000000..ea504d3
--- /dev/null
@@ -0,0 +1 @@
+Fixed reference leak in the finalization of :mod:`tkinter`.
index 1542d3af42f7550a22eadf780d8119bd8025eae5..e1e81082d9ec470366e0f9daf4243845a9053526 100644 (file)
@@ -3389,17 +3389,28 @@ DisableEventHook(void)
 #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 = {
     PyModuleDef_HEAD_INIT,
-    "_tkinter",
-    NULL,
-    -1,
-    moduleMethods,
-    NULL,
-    NULL,
-    NULL,
-    NULL
+    .m_name = "_tkinter",
+    .m_methods = moduleMethods,
+    .m_clear = module_clear,
+    .m_free = module_free
 };
 
 PyMODINIT_FUNC