summaryrefslogtreecommitdiffstats
path: root/generic/tclLiteral.c
diff options
context:
space:
mode:
authorKevin B Kenny <kennykb@acm.org>2004-07-21 00:42:37 (GMT)
committerKevin B Kenny <kennykb@acm.org>2004-07-21 00:42:37 (GMT)
commitb7baa5cf544d8865daa4745ad9616caabfedd664 (patch)
tree497cd829d08b8227765ef2485af55dd5733a6147 /generic/tclLiteral.c
parent1588001f922d15b8d69b00506ab0260f81595b8f (diff)
downloadtcl-b7baa5cf544d8865daa4745ad9616caabfedd664.zip
tcl-b7baa5cf544d8865daa4745ad9616caabfedd664.tar.gz
tcl-b7baa5cf544d8865daa4745ad9616caabfedd664.tar.bz2
2004-07-21 Kevin Kenny <kennykb@acm.org>
* generic/tclBasic.c (DeleteInterpProc): * generic/tclLiteral.c (TclCleanupLiteralTable): * generic/tclInt.h: added a TclCleanupLiteralTable function, called from DeleteInterpProc, that frees internal representations of shared literals early when an interpreter is being deleted. This change corrects a number of memory mismanagement issues in the cases where the internal representation of one literal contains a reference to another, and avoids conditions such as resolved variable names referring to procedure and namespace contexts that no longer exist. [Bug 994838]
Diffstat (limited to 'generic/tclLiteral.c')
-rw-r--r--generic/tclLiteral.c55
1 files changed, 54 insertions, 1 deletions
diff --git a/generic/tclLiteral.c b/generic/tclLiteral.c
index c887067..58ef176 100644
--- a/generic/tclLiteral.c
+++ b/generic/tclLiteral.c
@@ -8,11 +8,12 @@
* that appears in tclHash.c.
*
* Copyright (c) 1997-1998 Sun Microsystems, Inc.
+ * Copyright (c) 2004 by Kevin B. Kenny. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
* of this file, and for a DISCLAIMER OF ALL WARRANTIES.
*
- * RCS: @(#) $Id: tclLiteral.c,v 1.18 2004/07/15 18:31:34 kennykb Exp $
+ * RCS: @(#) $Id: tclLiteral.c,v 1.19 2004/07/21 00:42:39 kennykb Exp $
*/
#include "tclInt.h"
@@ -78,6 +79,58 @@ TclInitLiteralTable(tablePtr)
/*
*----------------------------------------------------------------------
*
+ * TclCleanupLiteralTable --
+ *
+ * This procedure frees the internal representation of every
+ * literal in a literal table. It is called prior to deleting
+ * an interp, so that variable refs will be cleaned up properly.
+ *
+ * Results:
+ * None.
+ *
+ * Side effects:
+ * Each literal in the table has its internal representation freed.
+ *
+ *----------------------------------------------------------------------
+ */
+
+void
+TclCleanupLiteralTable( interp, tablePtr )
+ Tcl_Interp* interp; /* Interpreter containing literals to purge */
+ LiteralTable* tablePtr; /* Points to the literal table being cleaned */
+{
+ int i;
+ LiteralEntry* entryPtr;
+ LiteralEntry* nextPtr;
+ Tcl_Obj* objPtr;
+ Tcl_ObjType* typePtr;
+
+#ifdef TCL_COMPILE_DEBUG
+ TclVerifyGlobalLiteralTable( (Interp*) interp );
+#endif /* TCL_COMPILE_DEBUG */
+
+ for ( i = 0; i < tablePtr->numBuckets; i++ ) {
+ entryPtr = tablePtr->buckets[i];
+ while ( entryPtr != NULL ) {
+ objPtr = entryPtr->objPtr;
+ nextPtr = entryPtr->nextPtr;
+ typePtr = objPtr->typePtr;
+ if ( ( typePtr != NULL ) && ( typePtr->freeIntRepProc != NULL ) ) {
+ if ( objPtr->bytes == NULL ) {
+ Tcl_Panic( "literal without a string rep" );
+ }
+ objPtr->typePtr = NULL;
+ typePtr->freeIntRepProc( objPtr );
+ }
+ entryPtr = nextPtr;
+ }
+ }
+}
+
+
+/*
+ *----------------------------------------------------------------------
+ *
* TclDeleteLiteralTable --
*
* This procedure frees up everything associated with a literal table