diff options
author | ferrieux <ferrieux@noemail.net> | 2009-11-16 12:14:43 (GMT) |
---|---|---|
committer | ferrieux <ferrieux@noemail.net> | 2009-11-16 12:14:43 (GMT) |
commit | 0896106df25520af9ef13c454a8f6b1329a356ec (patch) | |
tree | c768bc39837f58df10cf53d8c7c937a8fc90c731 /generic/tclEncoding.c | |
parent | abe5d1ef78b12d0112b328433edfa40a5f4a5c47 (diff) | |
download | tcl-0896106df25520af9ef13c454a8f6b1329a356ec.zip tcl-0896106df25520af9ef13c454a8f6b1329a356ec.tar.gz tcl-0896106df25520af9ef13c454a8f6b1329a356ec.tar.bz2 |
Fix [Bug 2891556] and improve test to detect similar manifestations in the future.
FossilOrigin-Name: 68033c16fa0d035afa9a0eaad8b132e7b4ebca7f
Diffstat (limited to 'generic/tclEncoding.c')
-rw-r--r-- | generic/tclEncoding.c | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/generic/tclEncoding.c b/generic/tclEncoding.c index 1d4de73..b90e469 100644 --- a/generic/tclEncoding.c +++ b/generic/tclEncoding.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclEncoding.c,v 1.59.2.1 2008/07/04 19:22:21 jenglish Exp $ + * RCS: @(#) $Id: tclEncoding.c,v 1.59.2.2 2009/11/16 12:14:45 ferrieux Exp $ */ #include "tclInt.h" @@ -845,6 +845,9 @@ FreeEncoding( if (encodingPtr == NULL) { return; } + if (encodingPtr->refCount<=0) { + Tcl_Panic("FreeEncoding: refcount problem !!!"); + } encodingPtr->refCount--; if (encodingPtr->refCount == 0) { if (encodingPtr->freeProc != NULL) { @@ -3393,11 +3396,24 @@ EscapeFreeProc( if (dataPtr == NULL) { return; } - subTablePtr = dataPtr->subTables; - for (i = 0; i < dataPtr->numSubTables; i++) { - FreeEncoding((Tcl_Encoding) subTablePtr->encodingPtr); - subTablePtr++; - } + /* + * The subTables should be freed recursively in normal operation but not + * during TclFinalizeEncodingSubsystem because they are also present as a + * weak reference in the toplevel encodingTable (ie they don't have a +1 + * refcount for this), and unpredictable nuking order could remove them + * from under the following loop's feet [Bug 2891556]. + * + * The encodingsInitialized flag, being reset on entry to TFES, can serve + * as a "not in finalization" test. + */ + if (encodingsInitialized) + { + subTablePtr = dataPtr->subTables; + for (i = 0; i < dataPtr->numSubTables; i++) { + FreeEncoding((Tcl_Encoding) subTablePtr->encodingPtr); + subTablePtr++; + } + } ckfree((char *) dataPtr); } |