diff options
author | Miguel Sofer <miguel.sofer@gmail.com> | 2007-05-02 00:31:22 (GMT) |
---|---|---|
committer | Miguel Sofer <miguel.sofer@gmail.com> | 2007-05-02 00:31:22 (GMT) |
commit | e363ced3b4481084d34d11085cfd95b2bf71fe6c (patch) | |
tree | 745c0bd4700905a443b114003bb389e582fabe70 /generic/tclVar.c | |
parent | 17b8d2d3e3ac333f60da3b27fc34190d212670dd (diff) | |
download | tcl-e363ced3b4481084d34d11085cfd95b2bf71fe6c.zip tcl-e363ced3b4481084d34d11085cfd95b2bf71fe6c.tar.gz tcl-e363ced3b4481084d34d11085cfd95b2bf71fe6c.tar.bz2 |
* 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.
Diffstat (limited to 'generic/tclVar.c')
-rw-r--r-- | generic/tclVar.c | 9 |
1 files changed, 7 insertions, 2 deletions
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) { |