| Ticket UUID: | ff2ca8b34c922c42dea81e9bd7aaf89d23d09284 | |||
| Title: | Tk holds on to application names of deleted interpreters on macOS + segfault when sending to a "zombie" appname | |||
| Type: | Bug | Version: | 8.6.16 | |
| Submitter: | erikleunissen | Created on: | 2025-08-17 13:07:27 | |
| Subsystem: | 58. [send] | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Severe | |
| Status: | Pending | Last Modified: | 2026-09-25 09:16:01 | |
| Resolution: | Fixed | Closed By: | nobody | |
| Closed on: | ||||
| Description: |
Under macOS Tk doesn't remove the name of a child interp when it is deleted. Therefore, the list of interps returned by "winfo interp" grows steadily while child interpreters are created and deleted [*]. What's more, I see that tests winfo-5.4 and winfo-5.5 work around this issue. I wondered why the results for these test are defined in such a complicated manner. Now I understand. But if I'm right, it is contrary to the purpose of tests to hide bugs. And it is quite remarkable that these work-arounds are made for tests that run on all platforms, while the problem exists in just one platform. Lastly, when sending to a Tk application that exists in [winfo interps], but whose interp was actually deleted, the process segfaults. The following script (also attached as file exercise.tcl) demonstrates the faulty behaviour. -- package require Tk interp create child1 child1 eval { package require Tk tk appname foo1 } interp create child2 child2 eval { package require Tk tk appname foo2 } interp delete child1 interp delete child2 puts "winfo interps: |[winfo interps]|"; flush stdout send foo1 {set tcl_version} -- Output from a wish 8.6.16 on macOS: % wish exercise.tcl winfo interps: |foo2 foo1 exercise.tcl| zsh: segmentation fault wish exercise.tcl % -- [*] At some point in test file winfo.test in the Tk test suite the list of aplication reaches some 18 entries. | |||
| User Comments: |
serhiy.storchaka added on 2026-09-25 09:16:01:
Fixed in 9.1 by the mac_send merge [1574913cc7], as confirmed above. 8.6 and 9.0 still have the use-after-free found below, and there is no test yet (adapting winfo-5.4/5.5 was suggested). Pending a backport decision and a test. erikleunissen added on 2025-09-08 09:19:18: I'm withdrawing my overly suspicious remark implying that tests winfo-5.4 and 5.5 were cooked to make them pass on macOS. The somewhat complicated definition for the expected result is there to take any pre-existing Tk interpreters into account. (Courtesy to Marc Culler for pointing this out to me.) The fact that that same specific code is also the reason that a flaw on macOS goes undetected, is just an unanticipated side-effect. erikleunissen added on 2025-09-03 08:53:37: Or maybe adapting winfo-5.4 and winfo-5.5 suffices. erikleunissen added on 2025-09-03 08:51:05: Uhmm, not in send.test but better in winfo.test I think. erikleunissen added on 2025-09-03 08:39:48: Hi Marc, The output in the previous post is as it ought to be. So the issue doesn't exhibit anymore with your branch. I'd suggest to use the test script as a basis for a true test in send.test. marc_culler (claiming to be Marc Culler) added on 2025-09-03 02:48:00: Running the test script in the mac_send branch produces:
winfo interps: |exercise.tcl|
Error in startup script: no application named "foo1"
while executing
"send foo1 {set tcl_version}"
(file "../exercise.tcl" line 15)
There is no segfault.
chrstphrchvz added on 2025-08-17 20:13:29: Using AddressSanitizer, I can confirm the example script triggers use-after-free of stale pointers to a deleted interpreter. In Tk_SetAppName() there is an old comment TODO: DeleteProc. Presumably the never-implemented DeleteProc() is where such pointers to deleted interpreters would be cleaned up. | |||
Attachments:
- exercise.tcl [download] added by erikleunissen on 2025-08-17 14:14:32. [details]
