aboutsummaryrefslogtreecommitdiff
path: root/jim.c
diff options
context:
space:
mode:
authorSteve Bennett <steveb@workware.net.au>2017-08-07 22:57:47 +1000
committerSteve Bennett <steveb@workware.net.au>2017-08-07 22:58:04 +1000
commit9f5d7e0d683f140e4a735a2f357c167a83819050 (patch)
tree8195a88824ab5aca8976585a5f6a0a361f046457 /jim.c
parentbbe51b64485764195f4fa3be4dee240fb6b66e34 (diff)
downloadjimtcl-9f5d7e0d683f140e4a735a2f357c167a83819050.zip
jimtcl-9f5d7e0d683f140e4a735a2f357c167a83819050.tar.gz
jimtcl-9f5d7e0d683f140e4a735a2f357c167a83819050.tar.bz2
jim: Fix ref count issue with dict-subst
When a dict-subst object is duplicated, ref counts need to be adjusted. Reported-by: Ryan Whitworth <me@ryanwhitworth.com> Signed-off-by: Steve Bennett <steveb@workware.net.au
Diffstat (limited to 'jim.c')
-rw-r--r--jim.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/jim.c b/jim.c
index ea70d35..4070206 100644
--- a/jim.c
+++ b/jim.c
@@ -2307,11 +2307,12 @@ static void JimSetStringBytes(Jim_Obj *objPtr, const char *str)
}
static void FreeDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *objPtr);
+static void DupDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr);
static const Jim_ObjType dictSubstObjType = {
"dict-substitution",
FreeDictSubstInternalRep,
- NULL,
+ DupDictSubstInternalRep,
NULL,
JIM_TYPE_NONE,
};
@@ -4875,6 +4876,15 @@ void FreeDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *objPtr)
Jim_DecrRefCount(interp, objPtr->internalRep.dictSubstValue.indexObjPtr);
}
+static void DupDictSubstInternalRep(Jim_Interp *interp, Jim_Obj *srcPtr, Jim_Obj *dupPtr)
+{
+ /* Copy the internal rep */
+ dupPtr->internalRep = srcPtr->internalRep;
+ /* Need to increment the ref counts */
+ Jim_IncrRefCount(dupPtr->internalRep.dictSubstValue.varNameObjPtr);
+ Jim_IncrRefCount(dupPtr->internalRep.dictSubstValue.indexObjPtr);
+}
+
/* Note: The object *must* be in dict-sugar format */
static void SetDictSubstFromAny(Jim_Interp *interp, Jim_Obj *objPtr)
{