summaryrefslogtreecommitdiffstats
path: root/generic/tclProc.c
diff options
context:
space:
mode:
authorandreas_kupries <akupries@shaw.ca>2008-08-11 20:40:32 (GMT)
committerandreas_kupries <akupries@shaw.ca>2008-08-11 20:40:32 (GMT)
commitca80199d12c1842a8046ed38269b20bbdbe2ca80 (patch)
tree240f6d1e24ef6dae6269f98ca53d8d0340a1742b /generic/tclProc.c
parent60540fe921222a09d82443fcf37083e68e566afa (diff)
downloadtcl-ca80199d12c1842a8046ed38269b20bbdbe2ca80.zip
tcl-ca80199d12c1842a8046ed38269b20bbdbe2ca80.tar.gz
tcl-ca80199d12c1842a8046ed38269b20bbdbe2ca80.tar.bz2
* generic/tclProc.c (Tcl_ProcObjCmd): Fixed memory leak triggered
* tests/proc.test: by procbody::test::proc. See [Bug 2043636]. Added a test case demonstrating the leak before the fix. Fixed a few spelling errors in test descriptions as well.
Diffstat (limited to 'generic/tclProc.c')
-rw-r--r--generic/tclProc.c26
1 files changed, 23 insertions, 3 deletions
diff --git a/generic/tclProc.c b/generic/tclProc.c
index bee78ca..9427f55 100644
--- a/generic/tclProc.c
+++ b/generic/tclProc.c
@@ -12,7 +12,7 @@
* See the file "license.terms" for information on usage and redistribution of
* this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclProc.c,v 1.157 2008/08/10 15:58:58 msofer Exp $
+ * RCS: @(#) $Id: tclProc.c,v 1.158 2008/08/11 20:40:40 andreas_kupries Exp $
*/
#include "tclInt.h"
@@ -255,6 +255,7 @@ Tcl_ProcObjCmd(
if (contextPtr->line
&& (contextPtr->nline >= 4) && (contextPtr->line[3] >= 0)) {
int isNew;
+ Tcl_HashEntry* hePtr;
CmdFrame *cfPtr = (CmdFrame *) ckalloc(sizeof(CmdFrame));
cfPtr->level = -1;
@@ -271,8 +272,27 @@ Tcl_ProcObjCmd(
cfPtr->cmd.str.cmd = NULL;
cfPtr->cmd.str.len = 0;
- Tcl_SetHashValue(Tcl_CreateHashEntry(iPtr->linePBodyPtr,
- (char *) procPtr, &isNew), cfPtr);
+ hePtr = Tcl_CreateHashEntry(iPtr->linePBodyPtr, (char *) procPtr,
+ &isNew);
+ if (!isNew) {
+ /*
+ * Get the old command frame and release it. See also
+ * TclProcCleanupProc in this file. Currently it seems as
+ * if only the procbodytest::proc command of the testsuite
+ * is able to trigger this situation.
+ */
+
+ CmdFrame* cfOldPtr = (CmdFrame *) Tcl_GetHashValue(hePtr);
+
+ if (cfOldPtr->type == TCL_LOCATION_SOURCE) {
+ Tcl_DecrRefCount(cfOldPtr->data.eval.path);
+ cfOldPtr->data.eval.path = NULL;
+ }
+ ckfree((char *) cfOldPtr->line);
+ cfOldPtr->line = NULL;
+ ckfree((char *) cfOldPtr);
+ }
+ Tcl_SetHashValue(hePtr, cfPtr);
}
/*