summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2016-03-01 16:45:01 (GMT)
committerdgp <dgp@users.sourceforge.net>2016-03-01 16:45:01 (GMT)
commitc761f885ddfb0bfdc09e27db3399acb1f1b65dbd (patch)
treef780a4fc2384f155fb49a9e432d1f54f4d1afe77
parent049650b5952e5e5ee1997772750450305dccc6d7 (diff)
parent7d6b4ece6967da652c3eeb1f0baced245473353b (diff)
downloadtcl-c761f885ddfb0bfdc09e27db3399acb1f1b65dbd.zip
tcl-c761f885ddfb0bfdc09e27db3399acb1f1b65dbd.tar.gz
tcl-c761f885ddfb0bfdc09e27db3399acb1f1b65dbd.tar.bz2
[80304238ac] Prevent RC cycle in the localVarName objtype.
-rw-r--r--generic/tclVar.c13
-rw-r--r--tests/var.test28
2 files changed, 36 insertions, 5 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c
index 451ef7b..5574f30 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -697,13 +697,16 @@ TclObjLookupVarEx(
/*
* An indexed local variable.
*/
+ Tcl_Obj *cachedNamePtr = localName(iPtr->varFramePtr, index);
part1Ptr->typePtr = &localVarNameType;
- if (part1Ptr != localName(iPtr->varFramePtr, index)) {
- part1Ptr->internalRep.twoPtrValue.ptr1 =
- localName(iPtr->varFramePtr, index);
- Tcl_IncrRefCount((Tcl_Obj *)
- part1Ptr->internalRep.twoPtrValue.ptr1);
+ if (part1Ptr != cachedNamePtr) {
+ part1Ptr->internalRep.twoPtrValue.ptr1 = cachedNamePtr;
+ Tcl_IncrRefCount(cachedNamePtr);
+ if (cachedNamePtr->typePtr != &localVarNameType
+ || cachedNamePtr->internalRep.twoPtrValue.ptr1 != NULL) {
+ TclFreeIntRep(cachedNamePtr);
+ }
} else {
part1Ptr->internalRep.twoPtrValue.ptr1 = NULL;
}
diff --git a/tests/var.test b/tests/var.test
index 0531746..b6b09fd 100644
--- a/tests/var.test
+++ b/tests/var.test
@@ -921,6 +921,34 @@ test var-22.0 {leak in array element unset: Bug a3309d01db} -setup {
rename getbytes {}
rename doit {}
} -result 0
+test var-22.1 {leak in localVarName intrep: Bug 80304238ac} -setup {
+ proc getbytes {} {
+ lindex [split [memory info] \n] 3 3
+ }
+ proc doit {} {
+ interp create slave
+ slave eval {
+ proc doit script {
+ eval $script
+ set foo bar
+ }
+ doit {foreach foo baz {}}
+ }
+ interp delete slave
+ }
+} -constraints memory -body {
+ set end [getbytes]
+ for {set i 0} {$i < 5} {incr i} {
+ doit
+ set tmp $end
+ set end [getbytes]
+ }
+ set leakedBytes [expr {$end - $tmp}]
+} -cleanup {
+ array unset A
+ rename getbytes {}
+ rename doit {}
+} -result 0
catch {namespace delete ns}