summaryrefslogtreecommitdiffstats
path: root/generic
diff options
context:
space:
mode:
Diffstat (limited to 'generic')
-rw-r--r--generic/tclVar.c12
1 files changed, 7 insertions, 5 deletions
diff --git a/generic/tclVar.c b/generic/tclVar.c
index 451ef7b..12e52c2 100644
--- a/generic/tclVar.c
+++ b/generic/tclVar.c
@@ -697,13 +697,15 @@ 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) {
+ TclFreeIntRep(cachedNamePtr);
+ }
} else {
part1Ptr->internalRep.twoPtrValue.ptr1 = NULL;
}