summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authordgp <dgp@users.sourceforge.net>2013-07-24 16:51:04 (GMT)
committerdgp <dgp@users.sourceforge.net>2013-07-24 16:51:04 (GMT)
commit7682f9c4cd7dfb3439a27d03b4531358798ff443 (patch)
tree3013ac88f88e9887ce2d74db6f4a50cfae8dde80 /tests
parentc81da08d4a5ddf07bf70bab9be966473b2520644 (diff)
downloadtcl-7682f9c4cd7dfb3439a27d03b4531358798ff443.zip
tcl-7682f9c4cd7dfb3439a27d03b4531358798ff443.tar.gz
tcl-7682f9c4cd7dfb3439a27d03b4531358798ff443.tar.bz2
Demonstrate and fix memory leak in Tcl_ParseVar().
Diffstat (limited to 'tests')
-rw-r--r--tests/parse.test21
1 files changed, 21 insertions, 0 deletions
diff --git a/tests/parse.test b/tests/parse.test
index 4605914..d7de5ff 100644
--- a/tests/parse.test
+++ b/tests/parse.test
@@ -23,6 +23,7 @@ testConstraint testparsevarname [llength [info commands testparsevarname]]
testConstraint testparsevar [llength [info commands testparsevar]]
testConstraint testasync [llength [info commands testasync]]
testConstraint testcmdtrace [llength [info commands testcmdtrace]]
+testConstraint memory [llength [info commands memory]]
test parse-1.1 {Tcl_ParseCommand procedure, computing string length} testparser {
testparser [bytestring "foo\0 bar"] -1
@@ -674,6 +675,26 @@ test parse-13.5 {Tcl_ParseVar procedure, error looking up variable} testparsevar
unset -nocomplain abc
list [catch {testparsevar {$abc([bogus x y z])}} msg] $msg
} {1 {invalid command name "bogus"}}
+test parse-13.6 {Tcl_ParseVar memory leak} -constraints memory -setup {
+ proc getbytes {} {
+ return [lindex [split [memory info] \n] 3 3]
+ }
+} -body {
+ set a() foo
+ set end [getbytes]
+ for {set i 0} {$i < 5} {incr i} {
+ set vn {}
+ set res [testparsevar [append vn $ a([string repeat {[]} 19]) bar]]
+ if {$res ne {foo bar}} {error "Unexpected result: $res"}
+
+ set tmp $end
+ set end [getbytes]
+ }
+ expr {$end - $tmp}
+} -cleanup {
+ unset -nocomplain a end i vn res tmp
+ rename getbytes {}
+} -result 0
test parse-14.1 {Tcl_ParseBraces procedure, computing string length} testparser {
testparser [bytestring "foo\0 bar"] -1