diff options
author | Steve Bennett <steveb@workware.net.au> | 2025-07-07 22:56:36 +1000 |
---|---|---|
committer | Steve Bennett <steveb@workware.net.au> | 2025-07-07 23:03:06 +1000 |
commit | 5b72bde554529818ca288d54deac63dd2e428483 (patch) | |
tree | 7af7ff60cf3a3f1ba2b23f8adf5a1e9a72afcbc5 /jim-pack.c | |
parent | 6c1d558d1df64683184c305250917490940a0062 (diff) | |
download | jimtcl-master-next.zip jimtcl-master-next.tar.gz jimtcl-master-next.tar.bz2 |
core: Jim_SetVariable() now frees value on errormaster-next
If the value has a zero reference count, free it in the error path.
Otherwise callers can't do: Jim_SetVariable(..., Jim_New...())
in case the object is leaked in the error path.
Fix various callers that were previously freeing the object in the
error path, and add a test to loop.test to show that this was not.
Signed-off-by: Steve Bennett <steveb@workware.net.au>
Diffstat (limited to 'jim-pack.c')
-rw-r--r-- | jim-pack.c | 8 |
1 files changed, 1 insertions, 7 deletions
@@ -371,7 +371,6 @@ static int Jim_PackCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) double fvalue; Jim_Obj *stringObjPtr; int len; - int freeobj = 0; if (Jim_GetEnum(interp, argv[3], options, &option, NULL, JIM_ERRMSG) != JIM_OK) { return JIM_ERR; @@ -406,10 +405,8 @@ static int Jim_PackCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) if (!stringObjPtr) { /* Create the string if it doesn't exist */ stringObjPtr = Jim_NewEmptyStringObj(interp); - freeobj = 1; } else if (Jim_IsShared(stringObjPtr)) { - freeobj = 1; stringObjPtr = Jim_DuplicateObj(interp, stringObjPtr); } @@ -455,10 +452,7 @@ static int Jim_PackCmd(Jim_Interp *interp, int argc, Jim_Obj *const *argv) } if (Jim_SetVariable(interp, argv[1], stringObjPtr) != JIM_OK) { - if (freeobj) { - Jim_FreeNewObj(interp, stringObjPtr); - return JIM_ERR; - } + return JIM_ERR; } return JIM_OK; } |