Tk Source Code

View Ticket
Login
Ticket UUID: 0625d100962d2faefd2631f6d18eed98fd701418
Title: Segmentation fault in menu-46.1 on MacOS
Type: Bug Version: 8.6.18, 9.0.5, 9.1.0
Submitter: jan.nijtmans Created on: 2026-10-20 14:01:10
Subsystem: 11. Aqua Menus Assigned To: nobody
Priority: 5 Medium Severity: Critical
Status: Closed Last Modified: 2026-10-22 14:21:38
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-22 14:21:38
Description:

I'm encountering the following on MacOS in testcase menu-46.1. Seen with Tk 8.6.18:

Thread 0 Crashed::  Dispatch queue: com.apple.main-thread
0   libobjcMsgSend.dylib          	       0x188438820 objc_msgSend + 32
1   Tk                            	       0x10349b3c4 TkpPostMenu + 376 (tkMacOSXMenu.c:1009)
2   Tk                            	       0x1033b60dc MenuWidgetObjCmd + 3272 (tkMenu.c:898)
3   Tcl                           	       0x10386ff70 Dispatch + 1160 (tclBasic.c:4513)
4   Tcl                           	       0x10386afe8 TclNRRunCallbacks + 168 (tclBasic.c:4549)
5   Tcl                           	       0x10386ad0c Tcl_EvalObjv + 88 (tclBasic.c:4268)
6   Tcl                           	       0x10386c540 TclEvalEx + 2732 (tclBasic.c:5420)
7   Tcl                           	       0x1039ab994 Tcl_FSEvalFileEx + 1180 (tclIOUtil.c:1827)
8   Tk                            	       0x103382e64 Tk_MainEx + 1756 (tkMain.c:332)
9   tktest                        	       0x102edc4f8 main + 88 (tkAppInit.c:93)
10  dyld                          	       0x1808e9158 start + 6688

Explanation: In TkpPostMenu(), A call to [menu itemAtIndex:itemIndex] is done without checking for menuPtr->tkwin == NULL first. Moving the check before the call remedies the segmentation fault.

User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-22 14:21:38:

Fixed by Jan in core-8-6-branch, core-9-0-branch, and main by commits [4ec896e8], [b9e98a45], and [4bbb759d]. Closing the ticket.


marc_culler (claiming to be Marc Culler) added on 2026-10-20 16:41:13:
Hi Jan,
I have been running the test suite a lot lately and have not seen that one.
But I'd say that you have found the cause of the crash.  Please add the
check for a null tkwin.