Do not release unallocated Tcl objects. Closes #117278 and #117167.
diff --git a/Modules/_tkinter.c b/Modules/_tkinter.c
index 528b048..86b5c22 100644
--- a/Modules/_tkinter.c
+++ b/Modules/_tkinter.c
@@ -572,13 +572,13 @@
objv = objStore;
if (args == NULL)
- objc = 0;
+ /* do nothing */;
else if (!PyTuple_Check(args)) {
- objc = 1;
objv[0] = AsObj(args);
if (objv[0] == 0)
goto finally;
+ objc = 1;
Tcl_IncrRefCount(objv[0]);
}
else {
@@ -588,6 +588,7 @@
objv = (Tcl_Obj **)ckalloc(objc * sizeof(char *));
if (objv == NULL) {
PyErr_NoMemory();
+ objc = 0;
goto finally;
}
}
@@ -599,8 +600,12 @@
break;
}
objv[i] = AsObj(v);
- if (!objv[i])
+ if (!objv[i]) {
+ /* Reset objc, so it attempts to clear
+ objects only up to i. */
+ objc = i;
goto finally;
+ }
Tcl_IncrRefCount(objv[i]);
}
}