| Ticket UUID: | afda09b5940134a86c7837dc40e8f781fa5b29f0 | |||
| Title: | windows crash of trunk | |||
| Type: | Bug | Version: | trunk | |
| Submitter: | nab | Created on: | 2023-12-20 14:47:15 | |
| Subsystem: | 13. Win Menus | Assigned To: | nobody | |
| Priority: | 5 Medium | Severity: | Important | |
| Status: | Closed | Last Modified: | 2026-10-22 17:22:38 | |
| Resolution: | Duplicate | Closed By: | serhiy.storchaka | |
| Closed on: | 2026-09-18 20:13:36 | |||
| Description: |
Hi,
I've decided to use Tcl+TK 9 for my app and thanks to 'Migrating Scripts to Tcl 9' and other ressources it was pretty easy.
I'm facing a crash on Windows (clang 17.0.6 installed by Msys2) that I never had before.
in my code at some point I have:
Tcl_EvalEx(x->interp, "destroy .menuBar.file.mru", -1, TCL_EVAL_DIRECT);
and this lead to this crash:
$ lldb /c/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe
(lldb) target create "C:/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe"
(rent executable set to 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.exe' (x
86_64).
(lldb) run
(lldb) Process 15192 launched: 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.
exe' (x86_64)
Process 15192 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa332fb447: Access violat
ion reading location 0x00000010
frame #0: 0x00007ffa332fb447 tcl9tk90.dll`ReconfigureWindowsMenu + 183
tcl9tk90.dll`ReconfigureWindowsMenu:
-> 0x7ffa332fb447 <+183>: movq (%rax,%rdi,8), %rbx
0x7ffa332fb44b <+187>: movq (%r14), %rax
0x7ffa332fb44e <+190>: movq %r12, %rcx
0x7ffa332fb451 <+193>: callq *0x3e0(%rax)
(lldb)
if I encapsulate the call in an after 0 [list ...], there's no crash
best regards,
nicolas
| |||
| User Comments: |
serhiy.storchaka added on 2026-09-18 20:13:36:
Most likely the same as [2d3a81c0], fixed in [c08e58fcfd] (8.6.15, 9.0.0): the menu freed in the entry command, and the entry destroyed afterwards rescheduled the reconfiguration for the freed menu. I could not reproduce with the current code under page heap, including destroying the menu from its own entry command. chrstphrchvz added on 2023-12-29 19:41:51: Currently I would guess that something is calling ScheduleMenuReconfigure() after Tcl_CancelIdleCall() was already called. I notice that there are currently only 2 checks for MENU_DELETION_PENDING, so there could be more checks which are missing. chrstphrchvz added on 2023-12-29 19:03:46: Looking again, I notice:
findProc = 0x00007ffa32277610 (tcl90.dll`BogusFind)
createProc = 0x00007ffa32277630 (tcl90.dll`BogusCreate)
This is done by Tcl_DeleteHashTable() during DestroyMenuInstance(). This means that TkpDestroyMenu() has also been called and menuPtr was likely freed. But then why did the idle call to ReconfigureWindowsMenu() not get canceled by TkpDestroyMenu()? nab added on 2023-12-29 06:28:30: Hi Christopher, I didn't manage to get Tcl && Tk compiled with Asan capabilities.... chrstphrchvz added on 2023-12-28 02:52:46: *menuPtr definitely appears corrupt. entries = 0x0000000000000010 explains “Access violation reading location 0x00000010” (so i is 0 when the crash occurs). Several other members are definitely invalid, including tkwin, display, and active. I am not aware what could be causing the corruption, though. I want to think menuPtr was not freed, because Tcl_CancelIdleCall(ReconfigureWindowsMenu, menuPtr) would have been called before menuPtr was freed. Are you able to use AddressSanitizer from MSYS2 Clang, i.e. compile both Tcl and Tk with -DPURIFY -fsanitize=address ? nab added on 2023-12-22 19:52:23: $ lldb /c/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe
(lldb) target create "C:/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe"
urrent executable set to 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.exe' (
x86_64).
(lldb) run
(lldb) Process 16052 launched: 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.
exe' (x86_64)
Process 16052 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa1a82ae3b: Access violat
ion reading location 0x00000010
frame #0: 0x00007ffa1a82ae3b tcl9tk90.dll`ReconfigureWindowsMenu(clientData=0x000002779777a990)
at tkWinMenu.c:601:10
598
599 count = menuPtr->numEntries;
600 for (i = 0; i < count; i++) {
-> 601 mePtr = menuPtr->entries[i];
602 lpNewItem = NULL;
603 flags = MF_BYPOSITION;
604 itemID = 0;
(lldb) expr *menuPtr
(TkMenu) $0 = {
tkwin = 0x0000000000000005
display = 0x0000000000000004
interp = 0x0000027797f813c0
widgetCmd = NULL
entries = 0x0000000000000010
numEntries = 3
active = 2712674178304
menuType = 0
menuTypePtr = 0x000000000000002c
borderPtr = 0x0000000000000003
borderWidthPtr = 0x0000027797f9be90
activeBorderPtr = NULL
activeBorderWidthPtr = 0x0000000000000031
reliefPtr = 0x0000000000000003
fontPtr = 0x0000027797faf1c0
fgPtr = NULL
disabledFgPtr = 0x000000000000006e
activeFgPtr = 0x0000000000000002
indicatorFgPtr = 0x0000027797f607a0
gray = 0
textGC = NULL
disabledGC = NULL
activeGC = 0x000002779777aa90
indicatorGC = 0x000002779777aa91
disabledImageGC = 0x000002779777aa92
totalWidth = -1753765229
totalHeight = 631
tearoff = 0
titlePtr = 0x0306020101010001
tearoffCommandPtr = 0x0104011326430000
takeFocusPtr = 0x0000027795256290
cursorPtr = 0x0000027795256230
postCommandPtr = 0x000002779474d2e0
postCommandGeneration = 218105856
menuFlags = 536871543
postedCascade = 0x00000277925f8080
nextInstancePtr = 0x00000277976e8cc0
mainMenuPtr = 0x0000027797b934a0
reserved1 = 0x0000027795256290
parentTopLevelPtr = 0x0000027795256230
menuRefPtr = 0x00000277976e9050
platformData = 0x00000277925f7f00
extensionPtr = 0x06090820090d0000
errorStructPtr = 0x000000ff2d3e0513
activeReliefPtr = 0x0000000010141495
items = {
buckets = 0x0000027797f39c70
staticBuckets = {
[0] = NULL
[1] = NULL
[2] = NULL
[3] = NULL
}
numBuckets = 16
numEntries = 0
rebuildSize = 48
mask = 15
downShift = 26
keyType = 0
findProc = 0x00007ffa32277610 (tcl90.dll`BogusFind)
createProc = 0x00007ffa32277630 (tcl90.dll`BogusCreate)
typePtr = NULL
}
serial = 36
}
(lldb)
chrstphrchvz added on 2023-12-22 19:00:06: The call to ReconfigureWindowsMenu() was scheduled by ScheduleMenuReconfigure and being done from the main loop, which seems fine. I wonder if the contents of *menuPtr make sense or appear corrupt. Could you please provide the output of expr *menuPtr from LLDB? nab added on 2023-12-22 08:14:48: here's what bt says:
Process 3076 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa1af3ae3b: Access violat
ion reading location 0x00000010
frame #0: 0x00007ffa1af3ae3b tcl9tk90.dll`ReconfigureWindowsMenu(clientData=0x0000012893f12930)
at tkWinMenu.c:601:10
598
599 count = menuPtr->numEntries;
600 for (i = 0; i < count; i++) {
-> 601 mePtr = menuPtr->entries[i];
602 lpNewItem = NULL;
603 flags = MF_BYPOSITION;
604 itemID = 0;
(lldb) bt
error: DLight.exe [0x0000000000002062]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x000000000000001a)
attribute, but range extraction failed (invalid range list offset 0x1a), please file a bug and attac
h the file at the start of this error message
thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa1af3ae3b: Access violati
on reading location 0x00000010
* frame #0: 0x00007ffa1af3ae3b tcl9tk90.dll`ReconfigureWindowsMenu(clientData=0x0000012893f12930)
at tkWinMenu.c:601:10
frame #1: 0x00007ffa1f79de56 tcl90.dll`TclServiceIdle + 118
error: DLight.exe [0x00000000000020b2]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x000000000000003b)
attribute, but range extraction failed (invalid range list offset 0x3b), please file a bug and attac
h the file at the start of this error message
frame #2: 0x00007ffa1f76408c tcl90.dll`Tcl_DoOneEvent + 380
error: DLight.exe [0x00000000000020ea]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x0000000000000046)
attribute, but range extraction failed (invalid range list offset 0x46), please file a bug and attac
h the file at the start of this error message
frame #3: 0x00007ffa1af860eb tcl9tk90.dll`Tk_MainLoop at tkEvent.c:2127:2
frame #4: 0x00007ffa1afc35fc tcl9tk90.dll`Tk_MainExW(argc=<unavailable>, argv=<unavailable>, app
InitProc=(DLight.exe`Tk_AppInit), interp=0x000001288ef05880) at tkMain.c:378:5
frame #5: 0x00007ff61024fc79 DLight.exe`wmain + 281
error: DLight.exe [0x0000000000002062]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x000000000000001a)
attribute, but range extraction failed (invalid range list offset 0x1a), please file a bug and attac
h the file at the start of this error message
frame #6: 0x00007ff60fe912f7 DLight.exe`__tmainCRTStartup
frame #7: 0x00007ff60fe913e6 DLight.exe`WinMainCRTStartup
frame #8: 0x00007ffa984a7344 kernel32.dll`BaseThreadInitThunk + 20
frame #9: 0x00007ffa99f226b1 ntdll.dll`RtlUserThreadStart + 33
error: DLight.exe [0x000000000000207a]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x0000000000000025)
attribute, but range extraction failed (invalid range list offset 0x25), please file a bug and attac
h the file at the start of this error message
(llb)[0; 1;31merror: DLight.exe [0x000000000000209d]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x0000
000000000030) attribute, but range extraction failed (invalid range list offset 0x30), please file a
bug and attach the file at the start of this error message
error: DLight.exe [0x00000000000020b2]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x000000000000003b)
attribute, but range extraction failed (invalid range list offset 0x3b), please file a bug and attac
h the file at the start of this error message
error: DLight.exe [0x00000000000020ea]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x0000000000000046)
attribute, but range extraction failed (invalid range list offset 0x46), please file a bug and attac
h the file at the start of this error message
error: DLight.exe [0x000000000000211e]: DIE has DW_AT_ranges(DW_FORM_sec_offset 0x0000000000000046)
attribute, but range extraction failed (invalid range list offset 0x46), please file a bug and attac
h the file at the start of this error message
(lldb)
chrstphrchvz added on 2023-12-21 20:09:55:
before the crash happens, GetMenuItemCount(winMenuHdl) have returned -1 Even though documentation says -1 indicates failure, maybe that is something Tk anticipates, and I think what is more important for this issue is how count is then assigned menuPtr->numEntries. Are you able to provide the full backtrace from LLDB? It would help to have some idea of when and where ReconfigureWindowsMenu() is called from. nab added on 2023-12-21 09:25:17: furthers puts and printf indicate that before the crash happens, GetMenuItemCount(winMenuHdl) have returned -1 ++ nab added on 2023-12-21 08:54:01: Hi Christopher,
I've recompiled Tk with CFLAGS="-fno-omit-frame-pointer -Og -g" and crashing place seems more evident:
$ lldb /c/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe
(lldb) target create "C:/Users/nico/dev/dlight/win64/dlight/build/DLight_Win64/bin/DLight.exe"
Current executable set to 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.exe'
(x86_64).
(lldb) run
(lldb) Process 2064 launched: 'C:\Users\nico\dev\dlight\win64\dlight\build\DLight_Win64\bin\DLight.e
xe' (x86_64)
Process 2064 stopped
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa2ddaae3b: Access violat
ion reading location 0x00000010
frame #0: 0x00007ffa2ddaae3b tcl9tk90.dll`ReconfigureWindowsMenu(clientData=0x00000142280ea990)
at tkWinMenu.c:601:10
598
599 count = menuPtr->numEntries;
600 for (i = 0; i < count; i++) {
-> 601 mePtr = menuPtr->entries[i];
602 lpNewItem = NULL;
603 flags = MF_BYPOSITION;
604 itemID = 0;
(lldb) bt 1
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffa2ddaae3b: Access violat
ion reading location 0x00000010
frame #0: 0x00007ffa2ddaae3b tcl9tk90.dll`ReconfigureWindowsMenu(clientData=0x00000142280ea990)
at tkWinMenu.c:601:10
(lldb)
++
chrstphrchvz added on 2023-12-21 01:45:41: …but “…location 0x00000010“ would also mean i is currently 2, and I do not see where menuPtr->entries may have suddenly become NULL in this loop, so my guess is probably wrong, although it was also based on callq *0x3e0(%rax) likely being a call to Tcl_DStringInit() via the Tcl stubs table. chrstphrchvz added on 2023-12-21 01:23:33:
0x7ffa332fb447 <+183>: movq (%rax,%rdi,8), %rbx I do not currently have easy access to Tk disassembly for Windows x64, but I believe this instruction is likely part the statement: mePtr = menuPtr->entries[i]; Here, “Access violation reading location 0x00000010” would mean that menuPtr->entries was NULL, but that is not supposed to happen because count was nonzero. chrstphrchvz added on 2023-12-20 23:48:48: Could you please provide a backtrace from LLDB? | |||
Home
Timeline
Branches
Tags
Forum
Tickets
Download
Wiki