Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Avoid possible memory leak in ``tkinter.c`` on Windows.
15 changes: 10 additions & 5 deletions Modules/_tkinter.c
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,20 @@ _get_tcl_lib_path(void)
}

/* Check expected location for an installed Python first */
tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
if (tcl_library_path == NULL) {
PyObject* tmp_tcl_library_path = PyUnicode_FromString("\\tcl\\tcl" TCL_VERSION);
if (tmp_tcl_library_path == NULL) {
Py_DECREF(prefix);
return NULL;
}
tcl_library_path = PyUnicode_Concat(prefix, tcl_library_path);
tcl_library_path = PyUnicode_Concat(prefix, tmp_tcl_library_path);
Py_DECREF(tmp_tcl_library_path);
Py_DECREF(prefix);
if (tcl_library_path == NULL) {
return NULL;
}
stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
if (stat_return_value == -2) {
Py_DECREF(tcl_library_path);
return NULL;
}
if (stat_return_value == -1) {
Expand All @@ -154,16 +156,17 @@ _get_tcl_lib_path(void)
}
stat_return_value = _Py_stat(tcl_library_path, &stat_buf);
if (stat_return_value == -2) {
Py_DECREF(tcl_library_path);
return NULL;
}
if (stat_return_value == -1) {
/* tcltkDir for a repository build doesn't exist either,
reset errno and leave Tcl to its own devices */
errno = 0;
tcl_library_path = NULL;
Py_CLEAR(tcl_library_path);
}
#else
tcl_library_path = NULL;
Py_CLEAR(tcl_library_path);
#endif
}
already_checked = 1;
Expand Down Expand Up @@ -707,11 +710,13 @@ Tkapp_New(const char *screenName, const char *className,
if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
str_path = _get_tcl_lib_path();
if (str_path == NULL && PyErr_Occurred()) {
Py_DECREF(v);
return NULL;
}
if (str_path != NULL) {
utf8_path = PyUnicode_AsUTF8String(str_path);
if (utf8_path == NULL) {
Py_DECREF(v);
return NULL;
}
Tcl_SetVar(v->interp,
Expand Down
Loading