diff options
author | Steve Bennett <steveb@workware.net.au> | 2017-08-07 22:57:47 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2017-08-07 22:58:04 +1000 |
commit | 9f5d7e0d683f140e4a735a2f357c167a83819050 (patch) | |
tree | 8195a88824ab5aca8976585a5f6a0a361f046457 /jim.c | |
parent | bbe51b64485764195f4fa3be4dee240fb6b66e34 (diff) | |
download | jimtcl-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.c | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -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) { |