Artifacts Associated With Ticket 3389764
Ticket change [1c4e89831c] (rid 90575) by dgp on 2011-08-10 19:01:33:
- assignee initialized to: "vincentdarley"
- cmimetype initialized to: "text/plain"
- comment initialized to:
$ valgrind --leak-check=yes --num-callers=10 ./tcltest ../tests/fCmd.test -match fCmd-4.5 ... ==16368== 344 (48 direct, 296 indirect) bytes in 1 blocks are definitely lost in loss record 22 of 23 ==16368== at 0x4A05E1C: malloc (vg_replace_malloc.c:195) ==16368== by 0x498624: Tcl_Alloc (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4FB37A: TclCreateLiteral (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4FB5B1: TclRegisterLiteral (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4ACF31: TclCompileVariableCmd (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4CE82F: TclCompileScript (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4D0A3B: TclSetByteCodeFromAny (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4D0B86: SetByteCodeFromAny (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x4479EE: TclProcCompileProc (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==16368== by 0x447C16: PushProcCallFrame (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest)
- 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: "dgp"
- subsystem initialized to: "37. File System"
- title initialized to: "fCmd-4.5 leaks"
- type initialized to: "Bug"
Ticket change [33d895a14d] (rid 106664) by dgp on 2011-08-11 02:52:58:
- assignee changed to: "dgp"
- icomment:
Reduced leaking script: package require tcltest tcltest::test foo desc {catch {file mkdir ""}} 1 - login: "dgp"
- mimetype: "text/plain"
- subsystem changed to: "47. Bytecode Compiler"
- username: "dgp"
Ticket change [63372235ce] (rid 92537) by dgp on 2011-08-11 03:33:14:
- icomment:
strangely, at least one point where the leak was introduced is in checkin [85f6cc0b99] (2009-07-26)
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7a50e54f9b] (rid 90295) by dkf on 2011-08-11 14:51:25:
- icomment:
Whatever is going on, as that's a patch of just Tcl code, it must be exposing an issue elsewhere.
- login: "dkf"
- mimetype: "text/plain"
- username: "dkf"
- icomment:
Ticket change [5446941fef] (rid 93921) by ferrieux on 2011-08-11 17:38:12:
- icomment:
Slowly getting to the offending object -- unfortunaltely the above stack is hit many times. However, I think the leaked literal is "". Indeed, if we replace the constant "" in the test with a global, the leak disappears: set empty "" test blah Blah -setup {} -constraints {} -returnCodes error -body { file mkdir $::empty } -result {can't create directory "": no such file or directory} - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [fa7e5a1886] (rid 91887) by ferrieux on 2011-08-11 17:57:37:
- icomment:
Continuing on this vein. Apparently the leak occurs when the "" shimmers from bytecode to path: package require tcltest proc bad s { puts [tcl::unsupported::representation $s] catch {file mkdir $s} puts [tcl::unsupported::representation $s] } set z "" tcltest::test blah Blah -setup { } -constraints { } -returnCodes error -body { #bad $::z bad "" } -result {can't create directory "": no such file or directory} Leaking case (bad ""): value is a bytecode with a refcount of 58, object pointer at 0x424bfb8, internal representation 0x43547c0:(nil), string representation "". value is a path with a refcount of 60, object pointer at 0x424bfb8, internal representation 0x52a1910:(nil), string representation "". Non-leaking case (bad $::z): value is a pure string with a refcount of 4, object pointer at 0x45918d0, string representation "". value is a path with a refcount of 6, object pointer at 0x45918d0, internal representation 0x52a0e88:(nil), string representation "". (note the +2 on refcount here is in both cases and is a red herring, due to errorstack conservation. can be avoided by sprinkling [catch {error foo}] in the code) - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [7f9435a599] (rid 97584) by ferrieux on 2011-08-11 18:01:31:
- icomment:
Hmm, "being a bytecode" is not sufficient, as is shown by adding "eval $::z". So I guess the criterion is rather belonging to different literal pools.
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [9e94da2c3e] (rid 96502) by dgp on 2011-08-11 21:51:16:
- icomment:
I'm at a loss. Starting again today, and the leak is simply gone. I do not get it.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [bf32d30260] (rid 102216) by dgp on 2011-08-11 21:57:03:
- icomment:
never mind. The testing recipe is too fragile for less than full attention.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [ae61d5c8fa] (rid 101630) by ferrieux on 2011-08-12 01:20:08:
- icomment:
Making progress: - I confirm that the leaked object is that hugely shared empty string - differential gdb-watching of its refcount (with and without the [file mkdir ""] line shows that the extra Incr is done by DupFsPathInternalRep at tclPathObj.c:2623 Maybe this leak is masked when the "" is from the other pool, being freed wholesale ?
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [52149673be] (rid 126248) by dgp on 2011-08-12 01:39:44:
- icomment:
Do we somehow end up with a cycle of paths? Where A has B as its translated form, and B has A as its translated form, and their mutual dependence prevents refcounts falling to 0 ?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [7429251de1] (rid 105162) by ferrieux on 2011-08-12 01:51:06:
- icomment:
Think I got it: (1) In TclByteCodeInit, the comment: /* * Prevent circular reference where the bytecode intrep of * a value contains a literal which is that same value. * If this is allowed to happen, refcount decrements may not * reach zero, and memory may leak. Bugs 467523, 3357771 */ explains why a Dup is done on the object (The Empty String, let's call it x0, shared 60 times). (2) At the time this Dup is done (for an obscure compilation of an empty body), the object has just shimmered to a Path (because of file mkdir), hence DupFsPathInternalRep is called. (3) However, x0 satisfies: x0->intrep->translatedPathPtr == x0 (4) Since DupFsPathInternalRep copies the translatedPathPtr, the result of the Dup is an object x1 such that x1->intrep->translatedPathPtr == x0 (5) As a consequence, the very thing that (1) was supposed to avoid, a reference loop, happens: the Dup has been too lazy. - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [3a59616c21] (rid 112549) by dgp on 2011-08-12 01:57:31:
- icomment:
Seems that a less wretched plan (nothing about the "path" type can be considered 'better' :) ) would be for the Dup of path containing an internal cycle to produce a new path that also contains an internal cycle, rather than containing links to the value just Dup'd .
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [18bc74c92d] (rid 122710) by dgp on 2011-08-12 01:58:32:
- icomment:
You want to try that, or shall I, or do you prefer something completely different?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [763ff60410] (rid 105545) by dgp on 2011-08-12 03:07:51:
- icomment:
Branch bug-3389764 has the proposed fix. With that patch in place, I see all of fCmd.test as leak free.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [676123e7d5] (rid 102891) by ferrieux on 2011-08-12 05:46:48:
- icomment:
Looks perfect to me :)
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [f1726648db] (rid 109365) by dgp on 2011-08-12 23:12:46:
- closedate changed to: "2011-08-12T16:12:46"
- closer changed to: "dgp"
- icomment:
allow_comments - 1
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- subsystem changed to: "36. Pathname Management"
- username: "dgp"