Tk Source Code

View Ticket
Login
2026-10-30
15:03 • Closed ticket [3515522f]: Crash when adding system menu to undocked window plus 10 other changes artifact: ee1c7e93 user: nemethi
14:55
Fix [351552]: "wm forget" did not release the menubar of the toplevel check-in: 9d8564a2 user: csaba tags: core-8-6-branch
2026-10-28
10:32
Fix [351552]: "wm forget" did not release the menubar of the toplevel check-in: c2f2b683 user: jan.nijtmans tags: core-9-0-branch
2026-10-27
16:07
Fix [351552]: "wm forget" did not release the menubar of the toplevel check-in: 42b7b7e9 user: jan.nijtmans tags: trunk, main
2026-10-25
07:53 • Ticket [3515522f] Crash when adding system menu to undocked window status still Open with 4 other changes artifact: 7a55d608 user: serhiy.storchaka
07:51
Fix [3515522fff]: [wm forget] did not release the menubar of the toplevel, so destroying it or the menu later crashed on Windows (TkWinGetWrapperWindow() dereferenced the NULL wmInfoPtr of the frame). The menubar is now 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 and wm-forget-2.3. closed check-in: 0a7452d8 user: serhiy.storchaka tags: wm-forget-release-menubar
2012-04-25
23:59 • Ticket [3515522f] Crash when adding system menu to undocked window status still Open with 4 other changes artifact: 3bc125b3 user: skylera
2012-04-06
16:30 • New ticket [3515522f]. artifact: cbdf3c4b user: skylera

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.