Tk Source Code

View Ticket
Login
Ticket UUID: 21944dba5eb3f7e4072e69757654d2c85806d456
Title: Aqua: NULL dereference crash in Tk_TopCoordsToWindow() when called by updatePointerForUnmap()
Type: Bug Version: trunk
Submitter: chrstphrchvz Created on: 2026-11-11 14:11:43
Subsystem: 82. X11 Emulation Assigned To: jan.nijtmans
Priority: 5 Medium Severity: Important
Status: Closed Last Modified: 2026-11-12 16:31:04
Resolution: Fixed Closed By: chrstphrchvz
    Closed on: 2026-11-12 16:31:04
Description:

I encountered this crash by running the widget demo and then pressing Command-Q to quit while the mouse pointer is over the demo list text widget. I have not ruled out that it does not occur at other times.

This short script recreates the affected widget demo usage:

ttk::frame .textFrame
text .t
pack .t -in .textFrame
pack .textFrame

The affected widget does not have to be a text widget, and does not have to be in the main toplevel. The use of -in seems important, while the particular geometry manager does not.

Backtrace:

    #0 0x000113c55c0a in Tk_TopCoordsToWindow tkMacOSXWm.c:5474
    #1 0x000113be43bf in updatePointerForUnmap tkMacOSXSubwindows.c:210
    #2 0x000113be3da3 in XUnmapWindow tkMacOSXSubwindows.c:472
    #3 0x00011320576d in Tk_UnmapWindow tkWindow.c:2007
    #4 0x00011318eb2d in PackStructureProc tkPack.c:1134
    #5 0x000113060161 in Tk_HandleEvent tkEvent.c:1262
    #6 0x0001131f7eb7 in Tk_DestroyWindow tkWindow.c:1578
    #7 0x0001131f7141 in Tk_DestroyWindow tkWindow.c:1519
    #8 0x0001131f7141 in Tk_DestroyWindow tkWindow.c:1519
    #9 0x00011321a5b0 in DeleteWindowsExitProc tkWindow.c:2986
    #10 0x00011306b94a in TkFinalizeThread tkEvent.c:2074
    #11 0x0001107ad164 in FinalizeThread tclEvent.c:1448
    #12 0x0001107ad392 in Tcl_FinalizeThread tclEvent.c:1419
    #13 0x0001107ac846 in Tcl_Finalize tclEvent.c:1254
    #14 0x000113b70f6a in TkpExitProc tkMacOSXInit.c:438
    #15 0x0001107ac756 in Tcl_Exit tclEvent.c:969
    #16 0x000113b52fea in ReallyKillMe tkMacOSXHLEvents.c:630
    #17 0x000110ae8768 in Tcl_ServiceEvent tclNotify.c:725
    #18 0x000110aebd3f in Tcl_DoOneEvent tclNotify.c:1064
    #19 0x00011306c3e7 in Tk_MainLoop tkEvent.c:2101
    #20 0x0001131353fe in Tk_MainEx tkMain.c:372
    #21 0x00010ec77282 in main tkAppInit.c:115
    #22 0x7ff80f08052f in start+0xbef (dyld:x86_64+0xfffffffffffde52f)

The relevant function updatePointerForUnmap() was recently introduced as part of TIP 765: f370e760. Returning early if TkMacOSXGetTkWindow() returns NULL avoids the crash, but I do not know if that is all that should be done.

User Comments: chrstphrchvz added on 2026-11-12 16:31:04:

I could not reproduce this problem on 9.0. I could reproduce it with [f370e760] but not [ae370f6d], so I think it only affected 9.1.


jan.nijtmans added on 2026-11-11 22:39:02:

Does 9.0 have the same problem?


jan.nijtmans added on 2026-11-11 22:34:38:

>......and should be removed.

Feel free to do some clean-ups, as follow-up!


marc_culler (claiming to be Marc Culler) added on 2026-11-11 21:05:10:
Jan, your fix looked fine and solved the problem, so I merged it into main.

chrstphrchvz added on 2026-11-11 19:20:43:

Checking for non-nil w in Tk_MacOSXGetTkWindow() is not needed since [(NSObject *)nil respondsToSelector:…] is always false. Returning early from mouseIsInTkWindow() makes sense, though.

I now notice near-duplicate functions in tkMacOSXSubwindows.c and tkMacOSXPointer.c:

  • Both have identical mouseIsInTkWindow().
  • updatePointerForMap() (tkMacOSXSubwindows.c) is nearly identical to TkMacOSXUpdatePointerAfterMap() (tkMacOSXPointer.c).
  • TkMacOSXUpdatePointerBeforeUnmap() (tkMacOSXPointer.c) is a newer version of updatePointerForUnmap() (tkMacOSXSubwindows.c, i.e. the one for this crash). Most of what is in updatePointerForUnmap() is still in XUnmapWindow() between #if 0/#endif.

I would think that the duplicates in tkMacOSXSubwindows.c were unintentionally left behind by d8d3959c and should be removed.


jan.nijtmans added on 2026-11-11 16:22:29:

Something like [6e72bf7e28|this]?