diff options
author | Steve Bennett <steveb@workware.net.au> | 2024-07-24 14:01:03 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2024-07-24 14:01:03 +1000 |
commit | 900eb0c79d67fcee9a25be79a2f13dea60a6428e (patch) | |
tree | ebf30baa183c05f018a50dd24a9dd0e0650fc6da | |
parent | 7f77bef65edafb99188f63fea547190fcc8d5c4a (diff) | |
download | jimtcl-900eb0c79d67fcee9a25be79a2f13dea60a6428e.zip jimtcl-900eb0c79d67fcee9a25be79a2f13dea60a6428e.tar.gz jimtcl-900eb0c79d67fcee9a25be79a2f13dea60a6428e.tar.bz2 |
leval: fix some reference counting issues
Signed-off-by: Steve Bennett <steveb@workware.net.au>
-rw-r--r-- | jim.c | 30 |
1 files changed, 20 insertions, 10 deletions
@@ -11202,27 +11202,37 @@ static Jim_Obj *JimParseListEval(Jim_Interp *interp, struct Jim_Obj *objPtr) tokens = Jim_Alloc(sizeof(ScriptToken) * wordtokens); for (j = 0; j < wordtokens; j++) { tokens[j].objPtr = Jim_NewStringObj(interp, tokenlist.list[i + j].token, tokenlist.list[i + j].len); + Jim_IncrRefCount(tokens[j].objPtr); tokens[j].type = tokenlist.list[i + j].type; } i += wordtokens; wordObjPtr = JimInterpolateTokens(interp, tokens, wordtokens, JIM_NONE); + + if (wordObjPtr) { + if (expand) { + /* Expand the word into multiple elements */ + Jim_IncrRefCount(wordObjPtr); + for (j = 0; j < Jim_ListLength(interp, wordObjPtr); j++) { + Jim_ListAppendElement(interp, listObj, Jim_ListGetIndex(interp, wordObjPtr, j)); + } + /* No longer need the list value */ + Jim_DecrRefCount(interp, wordObjPtr); + } + else { + Jim_ListAppendElement(interp, listObj, wordObjPtr); + } + } + for (j = 0; j < wordtokens; j++) { + Jim_DecrRefCount(interp, tokens[j].objPtr); + } Jim_Free(tokens); + if (wordObjPtr == NULL) { /* e.g. reference to a variable that doesn't exist */ ret = JIM_ERR; break; } - - if (expand) { - /* Expand the word into multiple elements */ - for (j = 0; j < Jim_ListLength(interp, wordObjPtr); j++) { - Jim_ListAppendElement(interp, listObj, Jim_ListGetIndex(interp, wordObjPtr, j)); - } - } - else { - Jim_ListAppendElement(interp, listObj, wordObjPtr); - } } if (ret != JIM_OK) { |