summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorferrieux <ferrieux@users.sourceforge.net>2009-11-16 12:14:44 (GMT)
committerferrieux <ferrieux@users.sourceforge.net>2009-11-16 12:14:44 (GMT)
commiteaaa5034bff48b8fd6162def1dd4b0020b7c46cc (patch)
treec768bc39837f58df10cf53d8c7c937a8fc90c731
parent29964f603b788e4be58ee964184a84854b3724be (diff)
downloadtcl-eaaa5034bff48b8fd6162def1dd4b0020b7c46cc.zip
tcl-eaaa5034bff48b8fd6162def1dd4b0020b7c46cc.tar.gz
tcl-eaaa5034bff48b8fd6162def1dd4b0020b7c46cc.tar.bz2
Fix [Bug 2891556] and improve test to detect similar manifestations in the future.
-rw-r--r--ChangeLog5
-rw-r--r--generic/tclEncoding.c28
-rw-r--r--tests/encoding.test3
3 files changed, 29 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 3c86f19..c5ed476 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2009-11-16 Alexandre Ferrieux <ferrieux@users.sourceforge.net>
+
+ * generic/tclEncoding.c: Fix [Bug 2891556] and improve test to detect
+ * tests/econding.test: similar manifestations in the future.
+
2009-11-12 Don Porter <dgp@users.sourceforge.net>
*** 8.5.8 TAGGED FOR RELEASE ***
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);
}
diff --git a/tests/encoding.test b/tests/encoding.test
index 02dc07a..4530580 100644
--- a/tests/encoding.test
+++ b/tests/encoding.test
@@ -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: encoding.test,v 1.27.4.1 2008/07/22 03:34:30 dgp Exp $
+# RCS: @(#) $Id: encoding.test,v 1.27.4.2 2009/11/16 12:14:45 ferrieux Exp $
package require tcltest 2
@@ -414,6 +414,7 @@ test encoding-24.2 {EscapeFreeProc on open channels} -constraints {
} -setup {
# Bug #524674 output
set file [makeFile {
+ encoding system cp1252; # Bug #2891556 crash revelator
fconfigure stdout -encoding iso2022-jp
puts ab\u4e4e\u68d9g
exit