-
-
Notifications
You must be signed in to change notification settings - Fork 31.8k
gh-123504: Fix reference leak in initialization of _tkinter
#123505
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
cddd021
a9eb482
36c65af
cc291e4
df9265f
4f1f4e4
a77abba
f35f2a0
fc34562
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Fixed reference leak in the finalization of :mod:`tkinter`. |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you define "clear", you should always define "travel". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to emit a warning or even raise an error at runtime? For example in Objects/typeobject.c, I added an assertion in _PyType_CheckConsistency(): if (type->tp_flags & Py_TPFLAGS_HAVE_GC) {
// bpo-44263: tp_traverse is required if Py_TPFLAGS_HAVE_GC is set.
// Note: tp_clear is optional.
CHECK(type->tp_traverse != NULL);
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like a good idea. For both types and modules. |
||
.m_free = module_free | ||
}; | ||
|
||
PyMODINIT_FUNC | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You removed
.m_size = -1,
but it's ok,m_size=0
also means "no module state".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a difference between 0 and -1 related to subinterpreters.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the difference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
From the documentation:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh I see, I forgot about this difference :-(