Tk Source Code

View Ticket
Login
Ticket UUID: 3515522
Title: Crash when adding system menu to undocked window
Type: Bug Version: 8.6.18, 9.0.5, 9.1.0
Submitter: skylera Created on: 2012-04-06 16:30:42
Subsystem: 13. Win Menus Assigned To: aku
Priority: 5 Medium Severity: Minor
Status: Closed Last Modified: 2026-10-30 15:03:55
Resolution: Fixed Closed By: nemethi
    Closed on: 2026-10-30 15:03:55
Description:
I have recreated this in a fresh pull from fossil core-8-5-branch yesterday. On a windows build, undocking a window, adding a system menu, and then redocking the window will cause a crash when the menubar is destroyed.

Here is a testcase:
toplevel .w
menu .m
.w configure -menu .m
menu .m.system
.m.system add command -label "sys test"
.m add cascade -label System -menu .m.system
wm forget .w
destroy .w

Few more details:
The equivalent in tcl8.4 (replacing wm forget .w w/ wm toplevel .w 0) works fine.
The crash occurs in TkWinGetWrapperWindow when a null wmInfoPtr is dereferenced.
I can avoid the crash by re-adding the call to TkFrameReleaseMenu in WmForgetCmd which didn't seem to make the move when WmToplevelCmd became WmForgetCmd, however i don't know if this is the proper solution.
User Comments: nemethi (claiming to be Csaba Nemethi) added on 2026-10-30 15:03:55:

Merged by Jan into main and core-9-0-branch by commits [42b7b7e9] and [c2f2b683]. Backported to core-8-6-branch by commit [9d8564a29. Closing the ticket.


serhiy.storchaka added on 2026-10-25 07:53:44:

Confirmed on Windows 11 with 8.6 and 9.1: the script crashes in TkWinGetWrapperWindow(). As you found, wm forget does not release the menubar, so the frame stays registered as its owner. On X11 this does not crash, but a new menu with the same name then creates a menubar clone inside the frame. Fixed on branch wm-forget-release-menubar [0a7452d86d]: the menubar is released when a toplevel becomes a frame, and TkWinGetWrapperWindow() returns NULL for a window which is not a toplevel. New tests wm-forget-2.2 (the crash) and wm-forget-2.3. Tested on Linux and Windows; not tested on macOS.


skylera added on 2012-04-25 23:59:27:
Any progress on this? The last line of my original post shows a possible solution, i just need some confirmation on whether that is the proper solution of if a different fix is required.