Tk Source Code

View Ticket
Login
Ticket UUID: 8e32cb7ece0f75da51c914ffe52ab02e41dc3fc0
Title: Aqua: window-2.12 crash
Type: Bug Version: 9.0.5, 9.1.0
Submitter: chrstphrchvz Created on: 2025-11-28 23:52:32
Subsystem: 66. Aqua Window Operations Assigned To: chrstphrchvz
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-10-29 20:05:40
Resolution: Fixed Closed By: marc_culler
    Closed on: 2026-10-29 20:05:40
Description:

On an older/slower Mac running macOS 10.15 Catalina, I encounter test window-2.12 consistently failing due to a NULL dereference crashing the subprocess. Output from subprocess (with sanitizers):

waiting
ringing the bell -> cannot invoke "bell" command: application has been destroyed
macosx/tkMacOSXInit.c:472:29: runtime error: member access within null pointer of type 'TkWindow' (aka 'struct TkWindow')
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior macosx/tkMacOSXInit.c:472:29
AddressSanitizer:DEADLYSIGNAL
=================================================================
==33128==ERROR: AddressSanitizer: SEGV on unknown address 0x000000000170 (pc 0x00010b0aa75c bp 0x7ffee572c1d0 sp 0x7ffee572c170 T0)
==33128==The signal is caused by a READ memory access.
==33128==Hint: address points to the zero page.
    #0 0x00010b0aa75c in showRootWindow tkMacOSXInit.c:472
    #1 0x00010c78c33d in TclServiceIdle tclTimer.c:751
    #2 0x00010c62928e in Tcl_DoOneEvent tclNotify.c:1037
    #3 0x00010c30d5ea in Tcl_UpdateObjCmd tclEvent.c:1982
    #4 0x00010bbdf2af in Dispatch tclBasic.c:4734
    #5 0x00010bbc1a4c in TclNRRunCallbacks tclBasic.c:4750
    #6 0x00010bbd43a7 in TclEvalObjEx tclBasic.c:6209
    #7 0x00010bbd4221 in Tcl_EvalObjEx tclBasic.c:6190
    #8 0x00010c793275 in AfterProc tclTimer.c:1182
    #9 0x00010c79594f in TimerHandlerEventProc tclTimer.c:593
    #10 0x00010c626788 in Tcl_ServiceEvent tclNotify.c:725
    #11 0x00010c629225 in Tcl_DoOneEvent tclNotify.c:1024
    #12 0x00010c3090c6 in Tcl_VwaitObjCmd tclEvent.c:1734
    #13 0x00010bbdf2af in Dispatch tclBasic.c:4734
    #14 0x00010bbc1a4c in TclNRRunCallbacks tclBasic.c:4750
    #15 0x00010bbc017d in Tcl_EvalObjv tclBasic.c:4488
    #16 0x00010bbcce3c in TclEvalEx tclBasic.c:5589
    #17 0x00010c5681ce in Tcl_FSEvalFileEx tclIOUtil.c:1793
    #18 0x00010a71f1aa in Tk_MainEx tkMain.c:325
    #19 0x00010a4d3d31 in main tkAppInit.c:115
    #20 0x7fff70bafcc8 in start+0x0 (libdyld.dylib:x86_64+0x1acc8)

==33128==Register values:
rax = 0x0000000000000170  rbx = 0x00007ffee572c220  rcx = 0x0000100000000000  rdx = 0x0000000000000000
rdi = 0x0000000000000000  rsi = 0x0000000000000000  rbp = 0x00007ffee572c1d0  rsp = 0x00007ffee572c170
 r8 = 0xffffff0000000000   r9 = 0x000000000000007c  r10 = 0x00007fff70cf3a00  r11 = 0x0000000000000202
r12 = 0x0000000000000000  r13 = 0x0000000000000000  r14 = 0x0000000000000000  r15 = 0x0000000000000000
AddressSanitizer can not provide additional info.
SUMMARY: AddressSanitizer: SEGV tkMacOSXInit.c:472 in showRootWindow
==33128==ABORTING

Without having looked into the issue any further, here is a possible quick fix:

--- macosx/tkMacOSXInit.c.orig
+++ macosx/tkMacOSXInit.c
@@ -469,6 +469,7 @@ static void showRootWindow(void *clientData) {
        return;
     }
     TkWindow *winPtr = TkMacOSXGetTkWindow(root);
+    if (!winPtr) return;
     WmInfo *wmPtr = winPtr->wmInfoPtr;
     if (wmPtr->hints.initial_state == NormalState) {
        [root makeKeyAndOrderFront:NSApp];
User Comments: marc_culler (claiming to be Marc Culler) added on 2026-10-29 20:05:40:
I am closing this since it was also fixed by the merge of the
macos-root-destroyed-early branch.

chrstphrchvz added on 2026-10-24 15:15:00:

I suggest putting a comment in the test above after 0 {destroy .} to say that specifying a delay of 0 is intentional and necessary, in hopes that if the test fails for someone in the future, they won’t try to increase the delay and potentially defeat the purpose of the test. Although I wonder if such a comment makes it good enough to have after 0 {destroy .} in window-2.12 and then not need a separate test.


marc_culler (claiming to be Marc Culler) added on 2026-10-24 14:34:49:
On macOS 27.0.1 with an M3 CPU the script in this ticket runs with no
issue with the macos-root-destroyed-early branch.

serhiy.storchaka added on 2026-10-24 10:39:54:

Fixed on branch macos-root-destroyed-early [996b73f3a3], for both this ticket and [aeb2ed51ab], as suggested there: the NSWindow is retained until showRootWindow() runs, and the handler does nothing if the Tk window is gone. New test window-2.13 runs the script from this ticket.

The test also found a background error on Windows: the console's idle script that erases the "% " prompt ran after the application was destroyed. That is fixed on the same branch.

Tested on Linux and Windows. I have no Mac, so could someone test it on macOS, preferably with sanitizers or NSZombieEnabled=YES?


chrstphrchvz added on 2025-11-30 03:09:18:

This is not a Catalina-specific issue. Example script:

package require Tk
after 1000 {set forever 1}
after 0 {destroy .}
puts "waiting"
vwait forever
puts "done waiting"

This script currently triggers [aeb2ed51], but if that issue is resolved/worked around, the script triggers this issue instead.