Skip to content
Tcl Source Code Artifact [2825f036d5]
Login

Artifact [2825f036d5]

Artifact 2825f036d584e7f275162f2784c619b37e8486e5e8e86721a78562f647358bc2:


--- a/generic/tclCmdAH.c
+++ b/generic/tclCmdAH.c
@@ -2876,6 +2876,14 @@
 		result = TCL_ERROR;
 		goto done;
 	    }
+	    /*
+	     * The copy is itself released by ForeachCleanup. A reference is
+	     * needed because the index proc of an abstract list may hand the
+	     * copy (or something it owns) back as an element, which a loop
+	     * variable then holds: without it the final TclDecrRefCount
+	     * frees an object that the variable still references.
+	     */
+	    Tcl_IncrRefCount(statePtr->aCopyList[i]);
 	    /* Don't compute values here, wait until the last moment */
 	    statePtr->argcList[i] = TclObjTypeLength(statePtr->aCopyList[i]);
 	} else {