From 477d1446c742c0dc8d659fe7cfed43c49faf83d6 Mon Sep 17 00:00:00 2001 From: dkf Date: Tue, 3 Aug 2004 21:46:50 +0000 Subject: Plug leak and clarify code --- ChangeLog | 3 +++ generic/tclNamesp.c | 19 +++++++++---------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/ChangeLog b/ChangeLog index 134fcbe..b169536 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,9 @@ * generic/tclNamesp.c (MakeCachedEnsembleCommand): Initialize the epoch field cached in the subcommand. [Bug 989298] + (NsEnsembleImplementationCmd): Plug a leak (thanks to Miguel Sofer + for spotting it with valgrind) and reduce the number of goto + labels to make the code clearer. 2004-08-02 Don Porter diff --git a/generic/tclNamesp.c b/generic/tclNamesp.c index e2e2d3f..e38f2da 100644 --- a/generic/tclNamesp.c +++ b/generic/tclNamesp.c @@ -21,7 +21,7 @@ * See the file "license.terms" for information on usage and redistribution * of this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclNamesp.c,v 1.43 2004/08/03 20:31:52 dkf Exp $ + * RCS: @(#) $Id: tclNamesp.c,v 1.44 2004/08/03 21:46:55 dkf Exp $ */ #include "tclInt.h" @@ -4813,7 +4813,8 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) if (ensembleCmd->nsPtr == ensemblePtr->nsPtr && ensembleCmd->epoch == ensemblePtr->epoch) { prefixObj = ensembleCmd->realPrefixObj; - goto runSubcommand; + Tcl_IncrRefCount(prefixObj); + goto runResultingSubcommand; } } } @@ -4900,7 +4901,6 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) MakeCachedEnsembleCommand(objv[1], ensemblePtr, fullName, prefixObj); } - runSubcommand: /* * Do the real work of execution of the subcommand by building an * array of objects (note that this is potentially not the same @@ -4923,7 +4923,7 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) ckfree((char *)tempObjv); return result; - unknownOrAmbiguousSubcommand: + unknownOrAmbiguousSubcommand: /* * Have not been able to match the subcommand asked for with a * real subcommand that we export. See whether a handler has been @@ -4979,14 +4979,10 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) if (Tcl_ListObjLength(interp, prefixObj, &prefixObjc) != TCL_OK) { Tcl_DecrRefCount(prefixObj); Tcl_AddErrorInfo(interp, - "\n while parsing result of ensemble unknown subcommand handler"); + "\n while parsing result of ensemble unknown subcommand handler"); return TCL_ERROR; } if (prefixObjc > 0) { - /* - * Not 'runSubcommand' because we want to get the - * object refcounting right. - */ goto runResultingSubcommand; } @@ -4994,6 +4990,7 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) * Namespace alive & empty result => reparse. */ + Tcl_DecrRefCount(prefixObj); goto restartEnsembleParse; } if (!Tcl_InterpDeleted(interp)) { @@ -5019,7 +5016,7 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) } } Tcl_AddErrorInfo(interp, - "\n result of ensemble unknown subcommand handler: "); + "\n result of ensemble unknown subcommand handler: "); Tcl_AddErrorInfo(interp, TclGetString(unknownCmd)); } else { Tcl_AddErrorInfo(interp, @@ -5030,12 +5027,14 @@ NsEnsembleImplementationCmd(clientData, interp, objc, objv) Tcl_Release(ensemblePtr); return TCL_ERROR; } + /* * Cannot determine what subcommand to hand off to, so generate a * (standard) failure message. Note the one odd case compared * with standard ensemble-like command, which is where a namespace * has no exported commands at all... */ + Tcl_ResetResult(interp); if (ensemblePtr->subcommandTable.numEntries == 0) { Tcl_AppendStringsToObj(Tcl_GetObjResult(interp), -- cgit v0.12