Artifacts Associated With Ticket 3034840
Ticket change [7c3f724763] (rid 97045) by egavilan on 2010-07-26 18:28:14:
- assignee initialized to: "nijtmans"
- cmimetype initialized to: "text/plain"
- comment initialized to:
When trying to run the code on http://wiki.tcl.tk/26735 with Tcl HEAD (updated today), using the wish8.6 interpreter, I can crash the program by closing the wish window with the mouse. $ gdb wish8.6 GNU gdb 6.8 Copyright (C) 2008 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "i486-slackware-linux"... (gdb) run memchan_2.tcl Starting program: /usr/local/bin/wish8.6 memchan_2.tcl [Thread debugging using libthread_db enabled] [New Thread 0xb7a25ab0 (LWP 555)] [New Thread 0xb79eeb90 (LWP 558)] Writing data into rc0 Reading data from rc1 **Hello World** Writing data into rc1 Reading data from rc0 **Hello There !!** <=== Close the "." wish window here Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0xb7a25ab0 (LWP 555)] 0xb7eacbed in UpdateStringOfList (listPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclListObj.c:1865 1865{ (gdb) bt #0 0xb7eacbed in UpdateStringOfList (listPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclListObj.c:1865 #1 0xb7eb784f in Tcl_GetString (objPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclObj.c:1636 #2 0xb7eb78d1 in Tcl_GetStringFromObj (objPtr=0x8072ab8, lengthPtr=0xbf2930d4) at /home/emiliano/src/tcl/generic/tclObj.c:1676 #3 0xb7eacc9e in UpdateStringOfList (listPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclListObj.c:1893 #4 0xb7eb784f in Tcl_GetString (objPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclObj.c:1636 #5 0xb7eb78d1 in Tcl_GetStringFromObj (objPtr=0x8072ab8, lengthPtr=0xbf2931c4) at /home/emiliano/src/tcl/generic/tclObj.c:1676 #6 0xb7eacc9e in UpdateStringOfList (listPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclListObj.c:1893 #7 0xb7eb784f in Tcl_GetString (objPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclObj.c:1636 #8 0xb7eb78d1 in Tcl_GetStringFromObj (objPtr=0x8072ab8, lengthPtr=0xbf2932b4) at /home/emiliano/src/tcl/generic/tclObj.c:1676 #9 0xb7eacc9e in UpdateStringOfList (listPtr=0x8072ab8) at /home/emiliano/src/tcl/generic/tclListObj.c:1893 Note that group #1, #2 and #3 repeats in #4, #5 and #6, and then the backtrace output repeats endlessly with these three lines. The problem doesn't appear when using the tclsh intepreter (I can interrupt the program with Ctrl-C, but it finalize without a crash. The system is Linux 2.6.27.7 - foundin initialized to: "obsolete: 8.6b1.1"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "egavilan"
- subsystem initialized to: "14. List Object"
- title initialized to: "Crash in UpdateStringOfList()"
- type initialized to: "Bug"
Ticket change [50821f4bdb] (rid 125983) by dkf on 2010-07-27 19:29:16:
- icomment:
Works for me with HEAD. Crashes in 8.5.2. (All on OSX/Intel.)
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [2ae02cf7cb] (rid 118647) by dkf on 2010-07-27 19:36:49:
- icomment:
Works for me with tip of 8.5 branch too.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [1898201c04] (rid 122688) by nijtmans on 2010-07-27 19:39:49:
- icomment:
I can reproduce this problem on Linux (Ubuntu), both with the 8.5 head and 8.6 head!
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment:
Ticket change [11fca58ea5] (rid 95240) by egavilan on 2010-07-27 22:05:09:
- icomment:
The problem doesn't happen when Tk is loaded dinamically into the tclsh interpreter via [package require Tk], only using the wish interpreter. Tried thread-enabled and thread-disabled builds, both crash.
- login: "egavilan"
- mimetype: "text/plain"
- username: "egavilan"
- icomment:
Ticket change [4c3f5ceb14] (rid 126852) by dgp on 2010-07-29 20:53:47:
- icomment:
This is an infinite loop created because a tclListType value somehow has itself as its own second element! A list value is not supposed to be an element of itself, and it's clearly an invalid state for a multi-element list to claim to me an element of itself. The failure here is not in the tclListType machinery, but it whatever code corrupted this value into an invalid state. Just based on the players involved, I'd point fingers in the general direction of how (reflected?) channels interact with exit cleanup. Another approach might be to `git bisect` to discover when this failure first showed up.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [053d6e5833] (rid 89023) by dgp on 2010-07-30 01:01:48:
- icomment:
Issue appears between the 8.5.3 and 8.5.4 releases of Tcl/Tk.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [6b5059a4b2] (rid 128308) by dgp on 2010-07-30 01:07:41:
- assignee changed to: "dkf"
- icomment:
Quick scan of the changes file fingers this as the most likely suspect: 2008-07-20 (enhancement)[2008248] dict->list preserve item intreps (pasadyn) dkf? Any chance a bug in that change could cause internal rep corruption where a list tries to make an element of itself? And then any hints what could trigger that bug?
- login: "dgp"
- mimetype: "text/plain"
- priority changed to: "8"
- username: "dgp"
Ticket change [9334177f5f] (rid 105779) by dgp on 2010-07-30 01:22:56:
- icomment:
That doesn't seem to be it. If I disable the optimized dict->list conversion code, the bug remains.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [b0dfb94b1e] (rid 98055) by dgp on 2010-07-30 02:05:06:
- assignee changed to: "andreas_kupries"
- icomment:
The invalid value traces back to the Tcl_SetReturnOptions() call in UnmarshallErrorResult(). Since I don't see anything obviously wrong there, I suspect the error goes back further and a corrupt value is getting marshalled in the first place. Still tracking...
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
Ticket change [f49a90e051] (rid 129946) by dgp on 2010-07-30 04:36:08:
- icomment:
The bug is almost certainly in the list surgery done in FixLevelCode().
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [19d75ff141] (rid 122858) by dgp on 2010-07-30 06:13:28:
- icomment:
Much worse than that. Somehow the same Tcl_Obj is being returned to the tclFreeObjList twice in a row, which leaves it pointing to itself as the next Tcl_Obj memory chunk to allocate. Hilarity ensues. The code which is making the bad push back onto the free list is the Tcl_DecrRefCount(maskObj); in ReflectWatch(), but it's not yet clear whether it's the sinner or the victim of even earlier corruption.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [ac89eb77c1] (rid 101315) by ferrieux on 2010-07-30 06:35:08:
- icomment:
in InvokeTclMethod, dead channel case, why are argOne and argTwo decr-ref'ed ? sinner candidate ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [58fe5b6748] (rid 117894) by dgp on 2010-07-30 06:35:38:
- icomment:
It is not safe to call InputTclMethod() with zero ref count arguments, but that's what ReflectWatch() does. The "design" of this code isn't fully clear to me, so I don't know whether the right fix is to add a Tcl_IncrRefCount() before that call (and check all the similar calls in the same source code file), or to revise InvokeTclMethod() itself.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [4eaace3acd] (rid 125681) by dgp on 2010-07-30 06:39:40:
- icomment:
Anyhow, just to confirm that is the root of the problem, I added the Tcl_IncrRefCount() call and the bug goes away. Leaving with aku to choose what fix is preferred.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [6248386453] (rid 92389) by dgp on 2010-07-30 06:39:43:
- priority changed to: "9 Immediate"
Ticket change [513b3ff1c0] (rid 126104) by dgp on 2010-07-30 06:49:18:
- icomment:
Come up on the chat that just adding a Tcl_IncrRefCount() isn't good enough to fix things when the rcPtr->interp == NULL case is in effect. Then we still would get two Decrs after one Incr and the same brokenness
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7e9c656ee2] (rid 97447) by dgp on 2010-07-30 06:55:16:
- icomment:
Bottom line is that InvokeTclMethod and its callers need a complete refCount management analysis and fixup.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [35fc504402] (rid 107040) by dgp on 2010-07-30 06:55:17:
- subsystem changed to: "27. Channel Types"
Ticket change [6de36eb1b1] (rid 128781) by andreas_kupries on 2010-07-30 21:53:12:
- icomment:
dgp - This is just a note that I have seen this thread. Thank you for your analysis. I'll do a review as quickly as possible. Note: tclIORTrans.c is structurally similar to tclIORChan.c which this bug is apparently about. As such it may have the same problem.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [e7b0bb3256] (rid 104510) by andreas_kupries on 2010-07-31 00:29:47:
- icomment:
> It is not safe to call InputTclMethod() with > zero ref count arguments, but that's what > ReflectWatch() does. Hm. Going through this I cannot see how that (maskObj with RC == 0) happens. The maskObj is created by DecodeEventMask() and this function runs Tcl_IncrRefCount immediately on it, in line 1975, causing RC == 1. I am looking at revision 1.49 of tclIORChan.c That being said, I do see that ReflectInput/Output and SeekWide invoke ITM with newly minted objects which have RC == 0. (Still have to look at Block and (Set/Get)Option).
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [9c48c35d15] (rid 96126) by andreas_kupries on 2010-08-04 02:04:49:
- icomment:
File Added - 382168: RefCountFlow
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "RefCountFlow" [5b49cca808] (rid 118297) by andreas_kupries on 2010-08-04 02:04:49.
Ticket change [79b96d42a3] (rid 90180) by andreas_kupries on 2010-08-04 02:07:52:
- icomment:
Based on the attached RefCountFlow notes of mine it seems that calling InvokeTclMethod (ITM) with an RC=0 Tcl_Obj should consistently delete it before returning. It is only for RC=1 that argOne, argTwo can be both deleted and kept, depending on the code path taken. 3. argOneObj (a) CCOC, modeObj, RC=1. RC-- @2194, deleted. RC++ @2225 RC=2, RC-- @2296, RC=1, kept. (b) RWatch, maskObj, RC=1 s.o. (c) RClose, --------------- (d) RGOpt, --------------- (e) RIn, toReadObj, RC=0 RC-- @2194, deleted. RC++ @2225 RC=1, RC-- @2296, RC=0, deleted. ChanCreateObjCmd() modeObj = DecodeEventMask() @1975 RC=1. InvokeTclMethod ( modeObj, NULL ) => resObj modeObj @593 RC-- /assumes ITM rc neutral to detail1. WRONG. *** modeObj - may and may not be deleted in ITM. CCOC = ChanCreateObjCmd RXXX = ReflectXXX We cannot simply remove the code block going from lines 2193 to 2198. While that would fix things for the case RC=1, consistently keeping the arg* Tcl_Obj's, for the case RC=0 it would then start failing, keeping / deleting the Tcl_Obj based on code path. Best thing we can do IMHO is to consistently call ITM with arg* Tcl_Obj which are RC=1, plus removing that code block. Then the objects are consistently kept, and the caller has to delete, i.e. cleanup, by doing its own DecrRefCount. Does this agree with your (dgp) analysis as well ? - login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [7e5bd2702c] (rid 97398) by dgp on 2010-08-04 03:07:44:
- icomment:
Committed test iocmd-32.2 which tests for this bug.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [ac7cabcf14] (rid 101302) by ferrieux on 2010-08-04 03:21:09:
- icomment:
Though I realize you weren't asking me ;-) I agree with the general spirit of restoring a zero-RC-effect contract for ITM. Those 2193-2198 were puzzling anyway. On a side note, we are again witnessing an effect of the tradition of zero-RC objects: pouring confusion.... I admit it may have been a smart (peephole) optimization, but we definitely lost in code clarity.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [f5a24e88e8] (rid 130147) by andreas_kupries on 2010-08-04 04:15:32:
- icomment:
My patch in the works is currently running through the testsuite. Before patch the core crashed the new test, after path the new test passes, and all other tests in ioCmd.test pass as well. Now the full testsuite is brought to bear. I will attach the patch for review, and then also look at tclIORTrans.c, which very very likely has the same issue. Because it is structurally identical and derived from tclIORChan.c. copypastamunged. I will see if a modified copy of 32.2 can crash IORTrans as well. At last backport to 8.5.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "tclIORChan.patch" [31568795ea] (rid 93409) by andreas_kupries on 2010-08-04 04:22:08.
Ticket change [7c12857cbc] (rid 97015) by andreas_kupries on 2010-08-04 04:22:08:
- icomment:
File Added - 382182: tclIORChan.patch
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [533e9841c8] (rid 93724) by andreas_kupries on 2010-08-04 04:22:34:
- icomment:
Full testsuite passed. Patch attached.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [34dab684b4] (rid 106818) by andreas_kupries on 2010-08-04 04:54:47:
- icomment:
File Added - 382184: tclIORTrans.patch
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "tclIORTrans.patch" [cfff3d701e] (rid 113089) by andreas_kupries on 2010-08-04 04:54:47.
Ticket change [01e3ed88d4] (rid 119562) by andreas_kupries on 2010-08-04 04:59:31:
- icomment:
Added patch for tclIORTrans.c. While this patch has a new test there is no crash, either before or after. It certainly shared the same structure, however most methods had no detail arguments, and those which have (read, write) are not called during deletion. So this change is simply a proactive cleanup.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Add attachment "tclIORChan.patch.85" [d0571b07c0] (rid 113159) by andreas_kupries on 2010-08-04 05:28:06.
Ticket change [5fd0aa245c] (rid 115884) by andreas_kupries on 2010-08-04 05:28:06:
- icomment:
File Added - 382189: tclIORChan.patch.85
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [d9785e9404] (rid 107620) by andreas_kupries on 2010-08-04 05:28:29:
- icomment:
And the IORChan patch for Tcl 8.5.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [b18b52428a] (rid 98166) by dgp on 2010-08-04 22:20:20:
- icomment:
Please commit the fixes.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [4a3736f246] (rid 126502) by andreas_kupries on 2010-08-04 23:39:04:
- icomment:
Ok, will do. Thanks.
- login: "andreas_kupries"
- mimetype: "text/plain"
- username: "andreas_kupries"
- icomment:
Ticket change [b9e125402b] (rid 129223) by andreas_kupries on 2010-08-04 23:49:24:
- closedate changed to: "2010-08-04T16:49:24"
- closer changed to: "andreas_kupries"
- icomment:
allow_comments - 1 And done.
- login: "andreas_kupries"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "andreas_kupries"