Tcl Source Code

View Ticket
Login
Ticket UUID: 103abf181eb01366c018e047d525d0d042c8c5c5
Title: regression since 9.0.4 brings leaks and hangs to bundled Itcl 4.3.8
Type: Bug Created on: 2026-11-16 15:02:47
Submitter: dgp Assigned to: jan.nijtmans
Subsystem: None Severity: Important
Priority: 5 Medium Last modified: 2026-11-17 14:41:41
Status: Closed Closed by: jan.nijtmans
Resolution: Fixed Closed on: 2026-11-17 14:41:41
Version: 9.0.5
Description:
$ cd tcl9.0.5/unix
$ ./configure --disable-shared --enable-symbols=mem
...
$ make
...
$ make tcltest
...
$ make test-packages
...
Testing package 'itcl4.3.8'
...
Tests began at 2026-11-16 09:56:04 EST
basic.test
...
widgetadaptor.test
LEAKED: 25365 bytes


and there it hangs.


This was working in the Tcl 9.0.4 release, which included the same Itcl 4.3.8
User Comments:
dgp added on 2026-11-16 15:19:35:
Bisecting finds the origin of the failure

2026-10-22 11:44:24 e44f1d0e87 BAD CURRENT
2026-10-21 10:58:34 ff7935f994 GOOD

This blames 

checkout:     e44f1d0e8723fa8810ccbcc6f873f78fcb2bab26 2026-10-22 11:44:24 UTC
parent:       ff7935f9946df91c93f8b98e8d153476ff9addfe 2026-10-21 10:58:34 UTC
child:        d6c0fa08a86069cff1ec134d991effd66923b686 2026-10-23 20:28:32 UTC
tags:         core-9-0-branch
comment:      Many tcltest improvements, [773924ffff], [811659ffff],
              [572400ffff], [8413e79232] and [1528500fff] (user: jan.nijtmans)

Which seems odd and unlikely.

dgp added on 2026-11-16 15:58:15:
The trunk exhibits the same failure, and it originates in
the corresponding checkin.

serhiy.storchaka added on 2026-11-16 17:52:41:

This is not a new bug: fixing [8413e79232] in [e44f1d0e87] exposed existing problems that the old tcltest behaviour had hidden.

Before, cleanupTests called exit in any interpreter where Tk was loaded. Itcl's tests/helpers.tcl runs each test file three times in a child interpreter to look for leaks. So in widgetadaptor.test and widgetclass.test the whole process exited after the first run, and three problems went unnoticed:

  • the other two runs never happened, so 118 tests were silently skipped (2255 instead of 2373);
  • the leak check never completed: the Tk widget tests leak 17149 bytes (widgetadaptor.test) and 12880 bytes (widgetclass.test) per run in a child interpreter;
  • helpers.tcl ends with return -code return and relied on that exit to end the process. Without it, the process waits in Tk's event loop.
Since [e44f1d0e87], tcltest no longer exits when a test file is sourced by another script, which is correct. All three runs complete, the leak is reported, and the process hangs.

This only shows when Tk can be loaded by the test processes; without Tk the Itcl tests pass. With exit instead of return -code return at the end of the leak-test branch in helpers.tcl, all 2373 Itcl tests pass and nothing hangs. The leaks are still reported and need a separate look, in Tk or in Itcl's widget code.


serhiy.storchaka added on 2026-11-16 22:17:57:

The hang is caused by Itcl's leak-test harness. widgetadaptor.test and widgetclass.test set their tk constraint with package require Tk in the main interpreter before calling loadTestedCommands. In the leak-test mode, tests/helpers.tcl runs the file in child interpreters and stops the main one with return -code return, but the main interpreter's Tk main window stays. When the script ends, Tcl_Main enters the Tk event loop and waits forever. The old tcltest hid this by exiting from the child interpreter.

This patch to Itcl destroys that window after the leak test:

--- tests/helpers.tcl
+++ tests/helpers.tcl
@@ -42,7 +42,14 @@
     if {$leak} {
       puts "LEAKED: $leak bytes"
     }
   }
   itcl_leaktest [info script]
+  # The test file may have loaded Tk in this interpreter (to set its tk
+  # constraint) before calling loadTestedCommands. Destroy its main
+  # window, or the application would wait in the Tk event loop when the
+  # script ends.
+  if {[info commands ::destroy] ne ""} {
+    destroy .
+  }
   return -code return
 }

With it, all 2373 Itcl 4.3.8 tests pass with Tk available and nothing hangs. The leak check still reports 17149 bytes for widgetadaptor.test and 12880 bytes for widgetclass.test.


serhiy.storchaka added on 2026-11-16 23:30:24:

The reported leaks have three sources:

  • Not real leaks: queued window events of the deleted child interpreter, freed once events are processed. Fix: update after interp delete i in helpers.tcl.
  • Itcl: several Tcl_Objs and argument arrays not freed in widgetadaptor and widget code (itclObject.c, itclParse.c, itclBuiltin.c).
  • Tk: every Tk_Init adds another thread exit handler, 24 bytes per interpreter that loads Tk; see Tk ticket 703a7fdda7.
With fixes for the first two, all 2373 Itcl tests pass with Tk, and the leak check reports only noise.


serhiy.storchaka added on 2026-11-17 00:01:53:

The Itcl fixes, for the hang, the false leak reports and the leaks in the widget code, are in Itcl branch leaktest-hang-and-leaks (Itcl ticket 9c3f652f29).


jan.nijtmans added on 2026-11-17 13:41:42:

This is fixed in itcl 4.3.9

Closing

Many thanks for the quick reaction!


dgp added on 2026-11-17 14:23:11:
In light of this experience, the changes.md file
should be edited to highlight the incompatibilities
of tcltest 2.6 that have the potential to break 
deployed test suites.

jan.nijtmans added on 2026-11-17 14:41:41:

Well, Serhiy wrote:

> This is not a new bug: fixing [8413e79232] in [e44f1d0e87] exposed existing problems that the old tcltest behaviour had hidden.

So the problem has always been in Itcl, only there was a bug in the old tcltest which made the the testcases passed which should have failed.

Conclusion: it's not an incompatibility in tcltest, it was failure to detect a real problem.