From f49d3b0163b3d9e07913cfabde26ed0e5c0adf7d Mon Sep 17 00:00:00 2001 From: "jan.nijtmans" Date: Sat, 29 Dec 2012 18:17:24 +0000 Subject: Fix correct cleanup in more situations, using a new macro TclFreeIfRefCountZero --- generic/tclDictObj.c | 4 ++-- generic/tclInt.h | 8 ++++++++ generic/tclListObj.c | 4 ++++ generic/tclVar.c | 4 +--- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/generic/tclDictObj.c b/generic/tclDictObj.c index eb3625e..6e6bd1d 100644 --- a/generic/tclDictObj.c +++ b/generic/tclDictObj.c @@ -2187,8 +2187,8 @@ DictIncrCmd( } else { Tcl_SetObjResult(interp, valuePtr); } - } else if (dictPtr->refCount == 0) { - Tcl_DecrRefCount(dictPtr); + } else { + TclFreeIfRefCountZero(dictPtr); } return code; } diff --git a/generic/tclInt.h b/generic/tclInt.h index 742d957..8568a4f 100644 --- a/generic/tclInt.h +++ b/generic/tclInt.h @@ -3962,6 +3962,14 @@ typedef const char *TclDTraceStr; } \ } while(0) +#define TclFreeIfRefCountZero(objPtr) \ + do { \ + Tcl_Obj *_objPtr = (objPtr); \ + if (!_objPtr->refCount) { \ + TclFreeObj(_objPtr); \ + } \ + } while(0) + #if defined(PURIFY) /* diff --git a/generic/tclListObj.c b/generic/tclListObj.c index 85737d5..07c4d11 100644 --- a/generic/tclListObj.c +++ b/generic/tclListObj.c @@ -581,6 +581,7 @@ Tcl_ListObjAppendElement( } result = SetListFromAny(interp, listPtr); if (result != TCL_OK) { + TclFreeIfRefCountZero(objPtr); return result; } } @@ -872,6 +873,9 @@ Tcl_ListObjReplace( int result = SetListFromAny(interp, listPtr); if (result != TCL_OK) { + for (i = 0; i < objc; i++) { + TclFreeIfRefCountZero(objv[i]); + } return result; } } diff --git a/generic/tclVar.c b/generic/tclVar.c index d8a7141..5533e86 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -1766,9 +1766,7 @@ Tcl_ObjSetVar2( varPtr = TclObjLookupVarEx(interp, part1Ptr, part2Ptr, flags, "set", /*createPart1*/ 1, /*createPart2*/ 1, &arrayPtr); if (varPtr == NULL) { - if (newValuePtr->refCount == 0) { - Tcl_DecrRefCount(newValuePtr); - } + TclFreeIfRefCountZero(newValuePtr); return NULL; } -- cgit v0.12