diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c index b622c158a48fac..a1071e5a5812f2 100644 --- a/Modules/_tkinter.c +++ b/Modules/_tkinter.c @@ -3549,11 +3549,13 @@ PyInit__tkinter(void) if (!ret && GetLastError() == ERROR_ENVVAR_NOT_FOUND) { str_path = _get_tcl_lib_path(); if (str_path == NULL && PyErr_Occurred()) { + Py_DECREF(m); return NULL; } if (str_path != NULL) { wcs_path = PyUnicode_AsWideCharString(str_path, NULL); if (wcs_path == NULL) { + Py_DECREF(m); return NULL; } SetEnvironmentVariableW(L"TCL_LIBRARY", wcs_path);