Artifacts Associated With Ticket 3386721fff
Ticket change [1a929e6f42] (rid 123003) by msofer on 2011-08-05 11:34:52:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
This script package require tcltest 2 namespace import -force ::tcltest::* testintobj set 0 1 interp create slave load {} Tcltest slave causes the following leak: 0: malloc (vg_replace_malloc.c:236) 1: TclpAlloc (tclAlloc.c:705) 2: Tcl_Alloc (tclCkalloc.c:1046) 3: Tcl_NewIntObj (tclObj.c:2410) 4: TestintobjCmd (tclTestObj.c:640) 5: TclNREvalObjv (tclBasic.c:4272) 6: TEBCresume (tclExecute.c:2789) 7: TclNRRunCallbacks (tclBasic.c:4314) 8: TclEvalObjEx (tclBasic.c:5885) 9: Tcl_EvalObjEx (tclBasic.c:5866) The script is the minimal thing I found while investigating a leak in execute.test, every line seems significant. - foundin initialized to: "obsolete: 8.6b2"
- is_private initialized to: "0"
- priority initialized to: "5 Medium"
- resolution initialized to: "None"
- status initialized to: "Open"
- submitter initialized to: "msofer"
- subsystem initialized to: "None"
- title initialized to: "leak in tcltest"
- type initialized to: "Bug"
Ticket change [2d57cef8f0] (rid 119051) by dgp on 2011-08-10 01:48:54:
- icomment:
No longer leaking in the trunk?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [85099b592a] (rid 131257) by dgp on 2011-08-10 01:48:55:
- assignee changed to: "msofer"
- closedate changed to: "2011-08-09T18:48:55"
- closer changed to: "dgp"
- resolution changed to: "Out of Date"
- status changed to: "Pending"
Ticket change [0a9a168e41] (rid 113852) by msofer on 2011-08-10 04:58:03:
- icomment:
Still there: mig@ari:~/DEVEL/tcl-core/trunk/unix$ /usr/bin/valgrind --leak-check=yes --num-callers=10 ./tcltest < /tmp/foo ==9650== Memcheck, a memory error detector ==9650== Copyright (C) 2002-2010, and GNU GPL'd, by Julian Seward et al. ==9650== Using Valgrind-3.6.0.SVN-Debian and LibVEX; rerun with -h for copyright info ==9650== Command: ./tcltest ==9650== ==9650== ==9650== HEAP SUMMARY: ==9650== in use at exit: 1,074 bytes in 26 blocks ==9650== total heap usage: 40,907 allocs, 40,881 frees, 3,898,487 bytes allocated ==9650== ==9650== 48 bytes in 1 blocks are definitely lost in loss record 23 of 26 ==9650== at 0x4C2815C: malloc (vg_replace_malloc.c:236) ==9650== by 0x4BCFA1: TclpAlloc (tclAlloc.c:705) ==9650== by 0x4CED10: Tcl_Alloc (tclCkalloc.c:1046) ==9650== by 0x4546B6: Tcl_NewIntObj (tclObj.c:2410) ==9650== by 0x422B18: TestintobjCmd (tclTestObj.c:640) ==9650== by 0x4C2C00: TclNREvalObjv (tclBasic.c:4269) ==9650== by 0x54B39C: TEBCresume (tclExecute.c:2793) ==9650== by 0x4C2D31: TclNRRunCallbacks (tclBasic.c:4311) ==9650== by 0x4C54E9: TclEvalObjEx (tclBasic.c:5882) ==9650== by 0x4C5479: Tcl_EvalObjEx (tclBasic.c:5863)
- login: "msofer"
- mimetype: "text/plain"
- resolution changed to: "None"
- status changed to: "Open"
- username: "msofer"
- icomment:
Ticket change [8b66bdc8ba] (rid 127562) by ferrieux on 2011-08-10 07:03:53:
- icomment:
OK, got it. In this test, there is a static array varPtr[] that holds the working values. When [load .. slave] is called, somehow the TclObjTest_Init() function is called a 2nd time, and that array is reset, overwriting the obj references. Now to understand how the LoadObjCmd code is supposed to prevent that double Init.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [d44922c8cb] (rid 123418) by ferrieux on 2011-08-10 17:57:44:
- icomment:
Ah, I realize now that the Init func of a package is supposed to be called once for each interp it is loaded in ... so clearly the fault here is the init proc's, which is not designed for this multiple-interp setup. Fix: move the varPtr array from static to per-interp storage. Never done this myself, appreciate a hand. Also, verify similar behavior in tons of other Tcltest subpackages ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [15dcfc6370] (rid 124636) by msofer on 2011-08-10 18:03:06:
- assignee changed to: "dgp"
- icomment:
assigning to the package expert so that he chimes in
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
Ticket change [077713b053] (rid 89405) by ferrieux on 2011-08-10 18:06:39:
- icomment:
Note that tclTest.c also has a few r/w statics. Also tclThreadTest.c has a few ones, though I cannot say they really are a threat (mainThreadID etc), by ignorance of realistic cases of concurrent/multiinterp loads of the Thread package.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [e43a195dc0] (rid 87919) by nijtmans on 2011-08-10 21:30:47:
- assignee changed to: "nijtmans"
- icomment:
>Fix: move the varPtr array from static to per-interp storage. Never done >this myself, appreciate a hand. The 'standard' way to deal with this is using TSD (Thread Specific Cata)
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
Ticket change [17ea6b8e7e] (rid 122576) by nijtmans on 2011-08-10 21:33:53:
- assignee changed to: "msofer"
- icomment:
Committed to trunk. Michael, does this help? Regards, Jan Nijtmans - login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
Ticket change [3bf631bef6] (rid 112842) by msofer on 2011-08-10 21:37:34:
- assignee changed to: "dgp"
- icomment:
nope, leak still present
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
Ticket change [25f68d6c5c] (rid 88257) by nijtmans on 2011-08-10 22:29:27:
- icomment:
Actually, that's not strange: The testintobj set 0 1 allocates a Tcl object in the TSD, but no-one throws it away!! Maybe we could create a "testclearall" command which clears all this storage as cleanup command after the test. Is there a way to define a cleanup callback when the thread ends?
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment:
Ticket change [32e18eb4be] (rid 93693) by nijtmans on 2011-08-10 22:33:14:
- icomment:
How about creating an exit handler using Tcl_CreateExitHandler(), which clears the storage? That should do the trick.
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment:
Ticket change [f67db7fdbd] (rid 130311) by ferrieux on 2011-08-10 23:16:59:
- icomment:
Jan, you're up the wrong tree :} There are two orthogonal things (1) the fact that the varPtr are never freed actively (2) the fact that two calls to TclTestObj_Init by two interps wreak havoc by overwriting the static array As it turns out, (1) is no problem because valgrind marks such blocks as "still reachable" (and there are a bunch of other such ones : a low priority endeavour), while here we're after the more ominous "definitely lost". And (2) is the real problem: an overwritten last reference to an object makes it definitely lost indeed. Note that using the TSD is not enough. As I said earlier, those data shoule be per-interp, not per-thread: there may be several interps in a single thread, as is notably the case here (a slave).
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [c378fc887c] (rid 111663) by dgp on 2011-08-10 23:43:18:
- icomment:
I still cannot reproduce the claimed leak. Will someone please reveal the complete recipe?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [5807b8d36d] (rid 117734) by ferrieux on 2011-08-10 23:53:03:
- icomment:
env CFLAGS=-DPURIFY ./configure && make clean && make tcltest valgrind ./tcltest foo.tcl
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [ca8176caeb] (rid 95358) by dgp on 2011-08-10 23:53:52:
- icomment:
Ok, that's what I'm doing. The script in this Tracker item does not leak.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7a4d16a64f] (rid 90294) by dgp on 2011-08-11 00:08:32:
- icomment:
--enable-symbols=all should not be used.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [6284527bbf] (rid 92416) by ferrieux on 2011-08-11 00:11:41:
- icomment:
OK, so to get back to the original problem, emiliano suggested RBC as an example of per-interp package init. It uses the assocdata hashtable to store its stuff.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [1def86b6ab] (rid 90890) by dgp on 2011-08-11 00:30:05:
- icomment:
Reverted the nijtmans commit. Comments here are correct. Moving to per-thread storage isn't the right fix. If getting the right fix is easy, by all means go ahead, and if someone's ambitious and lacks other tasks, go ahead and audit Tcltest for all the similar outdated coding that must lurk within (A very very large part of Tcltest has roots back to the days when "multiple interps" just could not happen, and were coded to the truths of the day). That said, I imagine most folks reading this comment have other tasks they could be doing that would be more important in getting 8.6.0 out the door. I will not block 8.6.0 because our testing tools are not as polished as we would like them to be.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [46740e1a63] (rid 99525) by ferrieux on 2011-08-11 01:25:18:
- icomment:
Fixed in HEAD, with assocdata.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [f58ee81922] (rid 130135) by ferrieux on 2011-08-11 01:25:19:
- closedate changed to: "2011-08-10T18:25:19"
- closer changed to: "ferrieux"
- resolution changed to: "Fixed"
- status changed to: "Closed"
Ticket change [35e3f96e8e] (rid 107016) by nijtmans on 2011-08-11 02:57:45:
- icomment:
Great work, Alex! Yes, that's much better!
- login: "nijtmans"
- mimetype: "text/plain"
- username: "nijtmans"
- icomment: