Index: ChangeLog ================================================================== --- ChangeLog +++ ChangeLog @@ -1,5 +1,10 @@ +2011-08-16 Don Porter + + * generic/tclCompile.c: [Bug 3392070] More complete prevention of + Tcl_Obj reference cycles when producing an intrep of ByteCode. + 2011-08-16 Donal K. Fellows * generic/tclListObj.c (TclLindexList, TclLsetFlat): Silence warnings about (unreachable) cases of uninitialized variables. * generic/tclCmdIL.c (SelectObjFromSublist): Improve the generation of Index: generic/tclCompile.c ================================================================== --- generic/tclCompile.c +++ generic/tclCompile.c @@ -2447,12 +2447,20 @@ /* * Prevent circular reference where the bytecode intrep of * a value contains a literal which is that same value. * If this is allowed to happen, refcount decrements may not * reach zero, and memory may leak. Bugs 467523, 3357771 + * + * NOTE: [Bugs 3392070, 3389764] We make a copy based completely + * on the string value, and do not call Tcl_DuplicateObj() so we + * can be sure we do not have any lingering cycles hiding in + * the intrep. */ - codePtr->objArrayPtr[i] = Tcl_DuplicateObj(objPtr); + int numBytes; + const char *bytes = Tcl_GetStringFromObj(objPtr, &numBytes); + + codePtr->objArrayPtr[i] = Tcl_NewStringObj(bytes, numBytes); Tcl_IncrRefCount(codePtr->objArrayPtr[i]); Tcl_DecrRefCount(objPtr); } else { codePtr->objArrayPtr[i] = envPtr->literalArrayPtr[i].objPtr; }