Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2016-10-30
08:31
[1ae12987cb] Ensure that deleting the [history] command deletes its storage. check-in: eb11bf9cb5 user: dkf tags: trunk
08:30 • Closed ticket [1ae12987cb]: Clean up history (::tcl::history) before/on exit (i.... artifact: 514c9ee9b5 user: dkf
08:22
[1ae12987cb] Ensure that deleting the [history] command deletes its storage. check-in: 3135d5681f user: dkf tags: core-8-6-branch
2016-10-21
14:37 • New ticket [1ae12987cb] Clean up history (::tcl::history) before/on exit (i.e., ... artifact: 0a165629c8 user: mr_calvin

Clean up history (::tcl::history) before/on exit (i.e., before exit handlers)

Closed / Fixed1ae12987cb21ae25cdb699d9c41d2596d8bd0035Created 10 years agoUpdated 10 years ago
Descriptionplain2016-10-21 14:37:03
The internal event storage of ::history (::tcl::history array) is not explicitly cleared when exiting (master interp, Tcl_Exit). Extensions' exit handlers, therefore, potentially see unbalanced refcounts on Tcl_Objs referenced from ::tcl::history.

See for an example http://paste.tclers.tk/3973.

Possible action items:
- call [::history::clear] on Tcl_Exit (not only for interp teardown).
- have [rename ::history {}] run the cleanup.

Excerpt from the IRC discussion with dgp and dkf ():

mr_calvin: (my main question basically is: why is an interactive tclsh not cleaning up the ::tcl::history at some early point during exit, before the exit handlers kick in.)

<dgp> IIRC, [history] is coded mostly (entirely?) in Tcl?

<dgp> And Tcl lacks good interface to exit handling.

mr_calvin: yeah … library/history.tcl

<dkf> Could just make Tcl_Main call [history clear] on the way out?

<dgp> no

<dkf> as handling all cases *very* hard

<dgp> this cleanup would normally be handled by interp teardown

<dgp> ....that [exit] does not tear down interps.

<dkf> if you have something that needs to be freed, you need an exit handler and those REQUIRE the C API to set up

dkf: as I wrote a little earlier. we do internal bookkeeping on Tcl_Objs intreps in NSF/NX, on exit, we draw the balance (exit handler) and references from tcl::history show up as unbalanced refcounts.

<dkf> but effectively we *know* there are references retained unless you finalize

mr_calvin: but doing a “unset -nocomplain ::tcl::history” in our exit handler would be one option (at least in our memdebug build) to balance those refcounts in time, wouldn’t it?

<dkf> [::history clear] would leave me happier 

<dgp> Does [rename history {}] do a cleanup?

<dkf> probably not

<dgp> that would be a bug worth fixing.
Referenced by2
  • eb11bf9cb5[1ae12987cb] Ensure that deleting the [history] command deletes its storage. check-in2016-10-30 08:31:21
  • 3135d5681f[1ae12987cb] Ensure that deleting the [history] command deletes its storage. check-in2016-10-30 08:22:13
dkfwiki2016-10-30 08:30:31

Adding a trace seems to do the deletion correctly; plain rename history {} now drops the references to objects in its storage and removes the rest of the history implementation as well. I can't guarantee that it will all clean up perfectly on exit, but Tcl doesn't make strong guarantees in that case anyway. You have to finalize the library to get that guarantee and that's not on the normal exit path.

Log in (anonymous is fine) to add a comment.