Artifacts Associated With Ticket 3392070fffffffffffffffffffffffffffffffff
Ticket change [586a015996] (rid 117799) by dgp on 2011-08-15 17:19:18:
- assignee initialized to: "dgp"
- cmimetype initialized to: "text/plain"
- comment initialized to:
This exercise of the test suite leaks: $ make valgrind TESTFLAGS='-file "regexpComp.test subst.test" -match "regexpComp-12.1 subst-3.2"' ... ==4233== 292 (48 direct, 244 indirect) bytes in 1 blocks are definitely lost in loss record 23 of 24 ==4233== at 0x4A05E1C: malloc (vg_replace_malloc.c:195) ==4233== by 0x498654: Tcl_Alloc (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x4FB2CA: TclCreateLiteral (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x44821F: InitLocalCache (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x4488F0: TclNRInterpProcCore (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x48E315: TclNRRunCallbacks (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x493E03: TclEvalEx (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==4233== by 0x494135: Tcl_EvalEx (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) Looking at the tests, I suspect the literal value "j" is leaking, but don't have anything more concrete than that yet.
- 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: "47. Bytecode Compiler"
- title initialized to: "literal leak in regexpComp/subst combination"
- type initialized to: "Bug"
Ticket change [34f3c94807] (rid 106828) by dgp on 2011-08-16 02:39:24:
- icomment:
Reduced leak demonstration... $ cat a.tcl source b.tcl $ cat b.tcl proc foo {} { regexp . x j return $j } foo subst \j $ valgrind ./tcltest a.tcl ... ==6105== 292 (48 direct, 244 indirect) bytes in 1 blocks are definitely lost in loss record 23 of 24 ==6105== at 0x4A05E1C: malloc (vg_replace_malloc.c:195) ==6105== by 0x498654: Tcl_Alloc (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4FB2CA: TclCreateLiteral (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4FB501: TclRegisterLiteral (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4CF24A: TclCompileTokens (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4CE6A6: TclCompileScript (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4D0A6B: TclSetByteCodeFromAny (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4D0BB6: SetByteCodeFromAny (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x4E5065: TclCompileObj (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) ==6105== by 0x494338: TclNREvalObjEx (in /local/tmp/dgp/fossil/tcl-only/unix/tcltest) Debugging prints show the literal "j" is not released by TclDeleteLiteralTable() due to a surplus refcount. - login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [019b8bbd48] (rid 119508) by hobbs on 2011-08-16 02:43:17:
- icomment:
Perhaps the hard-coded compiled regexp cache is never freed? This is process wide and size limited though, so not a big deal.
- login: "hobbs"
- mimetype: "text/plain"
- username: "hobbs"
- icomment:
Ticket change [fe74efb539] (rid 108594) by dgp on 2011-08-16 23:04:44:
- icomment:
Simpler, single-file demo that exonerates [regexp]: if 1 { proc foo {} { scan x %c j return $j } foo set subst subst $subst j } - login: "dgp"
- mimetype: "text/plain"
- title changed to: "literal leak with delayed compile [subst]"
- username: "dgp"
- icomment:
Ticket change [62217baa29] (rid 92362) by ferrieux on 2011-08-17 00:26:45:
- icomment:
The leaking case seems to be correlated with shimmering from localVarName to substCode: set repr ::tcl::unsupported::representation if 1 { proc foo {} { scan x %c j return $j } foo puts [$repr j] set subst subst $subst j puts [$repr j] } => value is a localVarName with a refcount of 5, object pointer at 0x4237408, internal representation (nil):(nil), string representation "j". value is a substcode with a refcount of 6, object pointer at 0x4237408, internal representation 0x423cad8:0x7, string representation "j". ==16322== definitely lost: 24 bytes in 1 blocks While (shimmering to List in between): set repr ::tcl::unsupported::representation if 1 { proc foo {} { scan x %c j return $j } proc bar x { llength $x } foo puts [$repr j] bar j puts [$repr j] set subst subst $subst j puts [$repr j] } => value is a localVarName with a refcount of 5, object pointer at 0x4237878, internal representation (nil):(nil), string representation "j". value is a list with a refcount of 5, object pointer at 0x4237878, internal representation 0x423d848:(nil), string representation "j". value is a substcode with a refcount of 5, object pointer at 0x4237878, internal representation 0x423dea0:0x7, string representation "j". ==16479== definitely lost: 0 bytes in 0 blocks - login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [d50660d676] (rid 123547) by dgp on 2011-08-17 00:44:44:
- icomment:
Lookie what DupLocalVarName does! Look familiar? The copied value keeps a reference to the original, so taking a dup to stop cycles doesn't get the job done.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [eacfcbce27] (rid 103431) by dgp on 2011-08-17 01:04:28:
- icomment:
This is suggesting that the "Dup to avoid a cycle" strategy is not sufficient. If we've got these issues in multiple internal Tcl_ObjTypes it's a near certainty that some extension Tcl_ObjTypes do as well, and we haven't had any explicit docs against the practice, have we?
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [b25856240f] (rid 98318) by dgp on 2011-08-17 02:13:28:
- icomment:
Confirmed that if I disable the "localVarName" type completely, the leak goes away while adding no failed tests. No idea what that does to performance or other matters though. The type must be there for a reason.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [ea5b586dd7] (rid 103362) by dgp on 2011-08-17 02:50:42:
- icomment:
Branch bug-3392070 holds a proposed fix.
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [2fffee7933] (rid 93170) by msofer on 2011-08-17 04:42:51:
- icomment:
Note that this code should be unchanged from Tcl8.5
- login: "msofer"
- mimetype: "text/plain"
- username: "msofer"
- icomment:
Ticket change [6792faea2c] (rid 102912) by dgp on 2011-08-17 19:40:21:
- closedate changed to: "2011-08-17T12:40:21"
- closer changed to: "dgp"
- icomment:
allow_comments - 1
- login: "dgp"
- mimetype: "text/plain"
- resolution changed to: "Fixed"
- status changed to: "Closed"
- username: "dgp"