Artifacts Associated With Ticket 3400944
Ticket change [b3029448b2] (rid 98442) by dgp on 2011-08-30 18:25:04:
- assignee initialized to: "hobbs"
- cmimetype initialized to: "text/plain"
- comment initialized to:
Even using the special support for valgrind (see 2919042) testing any script with [exit] in it is going to show leaks of things that would be freed by the natural unwinding that the [exit] prevents. For example, $ cat leak.tcl namespace eval foo exit $ valgrind --leak-check=yes ./tclsh leak.tcl ... ==13495== 36 bytes in 3 blocks are definitely lost in loss record 40 of 50 ==13495== at 0x4005903: malloc (vg_replace_malloc.c:195) ==13495== by 0x80DF060: TclpAlloc (tclAlloc.c:705) ==13495== by 0x80EF8C0: Tcl_Alloc (tclCkalloc.c:1046) ==13495== by 0x80E630A: TclArgumentEnter (tclBasic.c:5473) ==13495== by 0x80E5E98: TclEvalEx (tclBasic.c:5213) ==13495== by 0x80E54BE: Tcl_EvalEx (tclBasic.c:4872) ==13495== by 0x806D584: Tcl_FSEvalFileEx (tclIOUtil.c:1751) ==13495== by 0x8072F0F: Tcl_MainEx (tclMain.c:407) ==13495== by 0x8073573: Tcl_Main (tclMain.c:634) ==13495== by 0x805465B: main (tclAppInit.c:84) ==13495== ==13495== 201 (48 direct, 153 indirect) bytes in 2 blocks are definitely lost in loss record 47 of 50 ==13495== at 0x4005903: malloc (vg_replace_malloc.c:195) ==13495== by 0x80DF060: TclpAlloc (tclAlloc.c:705) ==13495== by 0x80EF8C0: Tcl_Alloc (tclCkalloc.c:1046) ==13495== by 0x808ED07: Tcl_NewStringObj (tclStringObj.c:340) ==13495== by 0x80817A3: TclSubstTokens (tclParse.c:2337) ==13495== by 0x80E5A63: TclEvalEx (tclBasic.c:5101) ==13495== by 0x80E54BE: Tcl_EvalEx (tclBasic.c:4872) ==13495== by 0x806D584: Tcl_FSEvalFileEx (tclIOUtil.c:1751) ==13495== by 0x8072F0F: Tcl_MainEx (tclMain.c:407) ==13495== by 0x8073573: Tcl_Main (tclMain.c:634) ==13495== by 0x805465B: main (tclAppInit.c:84) The same issue is present using [testthread exit].
- 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: "41. Memory Allocation"
- title initialized to: "[exit] creates leaks"
- type initialized to: "Bug"
Ticket change [4f30212f33] (rid 125783) by dgp on 2011-08-31 01:25:27:
- assignee changed to: "ferrieux"
Ticket change [87fc915d0d] (rid 131793) by dgp on 2011-08-31 01:30:05:
- icomment:
This is relevant to the `make valgrind` target. It takes the test suite to be a suitable body of code to cover seeking leaks. So long as the test suite includes use of [testthread exit] and similar things, though, leaks will be reported, likely false alarms. I suppose a constraint could be used to work around the matter. Hoping for better ideas.
- login: "dgp"
- mimetype: "text/plain"
- subsystem changed to: "53. Configuration and Build Tools"
- username: "dgp"
- icomment:
Ticket change [a28c656a91] (rid 109916) by dgp on 2011-08-31 02:33:46:
- icomment:
I see that the Thread package docs explicitly warn against the [thread::exit] command in favor of a preserve/release system. Lessons the testthread command could adopt, or the test suite could migrat from [testthread] to [package require Thread].
- login: "dgp"
- mimetype: "text/plain"
- username: "dgp"
- icomment:
Ticket change [5d4b4196a3] (rid 115440) by ferrieux on 2011-08-31 05:23:05:
- icomment:
This is similar to 3392735. Another facet :/
- login: "ferrieux"
- mimetype: "text/plain"
- username: "ferrieux"
- icomment:
Ticket change [e4deab9ff9] (rid 88031) by foxcruiser on 2011-08-31 20:20:06:
- icomment:
We got the same issue with [exit] when memory debugging XOTcl/NSF based on our test suite (with an internal refcounter and valgrind). We ended up with falling back to a graceful unwind instead of Tcl_Exit(), for the scope of test scripts: proc graceFullExit {{statuscode "1"}} { array set map {1 ok -1 error} set errorcode $map($statuscode) interp alias {} ::exit {} interp expose {} exit; return -code $errorcode -level [expr {[info level]-1}] "Test was exited with code $statuscode" } and then, before evaluating a test body: interp hide {} exit; interp alias {} ::exit {} ::graceFullExit works fine for us ... - login: "foxcruiser"
- mimetype: "text/plain"
- username: "foxcruiser"
- icomment:
Ticket change [aea4f0dafc] (rid 257766) by serhiy.storchaka on 2026-10-12 17:08:05:
- icomment:
Still true in 9.1: <code><nowiki>[exit]</nowiki></code> does not unwind the stack, so whatever the unwinding would free is reported by valgrind. A possible solution is to make <code><nowiki>[exit]</nowiki></code> unwind the stack, like <code>interp cancel -unwind</code>, and exit the process when the unwinding is complete. <code>catch</code> could not stop it, but <code>finally</code> clauses would run, so the script could clean up other resources, as with Python's <code>SystemExit</code> exception. This is a visible change in semantics and needs a TIP. The test suite problem was addressed as suggested here: tests which exit a thread in mid-operation have the <code>notValgrind</code> constraint, and <code><nowiki>[testthread exit]</nowiki></code> is no longer used in tests.
- login: "serhiy.storchaka"
- mimetype: "text/x-fossil-wiki"
- icomment: