|
2011-08-17
| ||
| 19:40 | • Closed ticket [3392070fff]: literal leak with delayed compile subst plus 7... artifact: 6792faea2c user: dgp | |
| 04:42 | • Ticket [3392070fff]: 4 changes artifact: 2fffee7933 user: msofer | |
| 02:50 | • Ticket [3392070fff]: 4 changes artifact: ea5b586dd7 user: dgp | |
| 02:13 | • Ticket [3392070fff]: 4 changes artifact: b25856240f user: dgp | |
| 01:04 | • Ticket [3392070fff]: 4 changes artifact: eacfcbce27 user: dgp | |
| 00:44 | • Ticket [3392070fff]: 4 changes artifact: d50660d676 user: dgp | |
| 00:26 | • Ticket [3392070fff]: 4 changes artifact: 62217baa29 user: ferrieux | |
|
2011-08-16
| ||
| 23:04 | • Ticket [3392070fff]: 5 changes artifact: fe74efb539 user: dgp | |
| 02:43 | • Ticket [3392070fff]: 4 changes artifact: 019b8bbd48 user: hobbs | |
| 02:39 | • Ticket [3392070fff]: 4 changes artifact: 34f3c94807 user: dgp | |
|
2011-08-15
| ||
| 17:19 | • New ticket [3392070fff]. artifact: 586a015996 user: dgp | |
literal leak with delayed compile [subst]
Closed / Fixed3392070fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2011-08-15 17:19:18
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.
dgpplain2011-08-16 02:39:24
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.
hobbsplain2011-08-16 02:43:17
Perhaps the hard-coded compiled regexp cache is never freed? This is process wide and size limited though, so not a big deal.
dgpplain2011-08-16 23:04:44
Simpler, single-file demo that exonerates [regexp]:
if 1 {
proc foo {} {
scan x %c j
return $j
}
foo
set subst subst
$subst j
}
ferrieuxplain2011-08-17 00:26:45
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
dgpplain2011-08-17 00:44:44
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.
dgpplain2011-08-17 01:04:28
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?
dgpplain2011-08-17 02:13:28
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.
dgpplain2011-08-17 02:50:42
Branch bug-3392070 holds a proposed fix.
msoferplain2011-08-17 04:42:51
Note that this code should be unchanged from Tcl8.5
dgpplain2011-08-17 19:40:21
allow_comments - 1
Log in (anonymous is fine) to add a comment.