From e363ced3b4481084d34d11085cfd95b2bf71fe6c Mon Sep 17 00:00:00 2001 From: Miguel Sofer Date: Wed, 2 May 2007 00:31:22 +0000 Subject: * generic/tclVar.c (TclPtrSetVar): fixed leak whenever newvaluePtr had refCount 0 and was used for appending (but not lappending). [Bug 1710710], thanks to mistachkin and kbk. --- ChangeLog | 6 ++++++ generic/tclVar.c | 9 +++++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 52f4119..15f200e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2007-05-01 Miguel Sofer + + * generic/tclVar.c (TclPtrSetVar): fixed leak whenever newvaluePtr + had refCount 0 and was used for appending (but not + lappending). [Bug 1710710], thanks to mistachkin and kbk. + 2007-05-01 Kevin B. Kenny * generic/tclIO.c (DeleteChannelTable): Made changes so that diff --git a/generic/tclVar.c b/generic/tclVar.c index b4fffb1..2e5f39d 100644 --- a/generic/tclVar.c +++ b/generic/tclVar.c @@ -15,7 +15,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclVar.c,v 1.132 2007/04/23 20:11:10 dgp Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.133 2007/05/02 00:31:22 msofer Exp $ */ #include "tclInt.h" @@ -1649,7 +1649,9 @@ TclPtrSetVar( } } else { /* append string */ /* - * We append newValuePtr's bytes but don't change its ref count. + * We append newValuePtr's bytes but don't change its ref count if + * non-zero; if newValuePtr has a zero refCount and we are not + * using the obj, be sure to free it to avoid a leak. */ if (oldValuePtr == NULL) { @@ -1663,6 +1665,9 @@ TclPtrSetVar( Tcl_IncrRefCount(oldValuePtr); /* since var is ref */ } Tcl_AppendObjToObj(oldValuePtr, newValuePtr); + if (newValuePtr->refCount == 0) { + Tcl_DecrRefCount(newValuePtr); + } } } } else if (newValuePtr != oldValuePtr) { -- cgit v0.12