From e6317236a4536bce3c36694afd134add51f2afdb Mon Sep 17 00:00:00 2001 From: msofer Date: Wed, 4 Sep 2002 15:18:53 +0000 Subject: * generic/tclVar.c (DeleteArray): leak plug [Bug 604239]. Thanks to dkf and dgp for the long and difficult discussion in the chat. FossilOrigin-Name: 2e3caf062150711b9e9ee168a74d91d6194bcde5 --- ChangeLog | 5 +++++ generic/tclVar.c | 15 ++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 0c2a2a2..d49c675 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2002-09-04 Miguel Sofer + + * generic/tclVar.c (DeleteArray): leak plug [Bug 604239]. Thanks + to dkf and dgp for the long and difficult discussion in the chat. + 2002-09-03 Jeff Hobbs * generic/tclVar.c (Tcl_UpVar2): code cleanup to not use goto diff --git a/generic/tclVar.c b/generic/tclVar.c index 516a558..9854161 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.65 2002/09/03 19:52:01 hobbs Exp $ + * RCS: @(#) $Id: tclVar.c,v 1.66 2002/09/04 15:18:53 msofer Exp $ */ #include "tclInt.h" @@ -4783,6 +4783,19 @@ DeleteArray(iPtr, arrayName, varPtr, flags) } TclSetVarUndefined(elPtr); TclSetVarScalar(elPtr); + + /* + * Even though array elements are not supposed to be namespace + * variables, some combinations of [upvar] and [variable] may + * create such beasts - see [Bug 604239]. This is necessary to + * avoid leaking the corresponding Var struct, and is otherwise + * harmless. + */ + + if (elPtr->flags & VAR_NAMESPACE_VAR) { + elPtr->flags &= ~VAR_NAMESPACE_VAR; + elPtr->refCount--; + } if (elPtr->refCount == 0) { ckfree((char *) elPtr); /* element Vars are VAR_IN_HASHTABLE */ } -- cgit v0.12