Skip to content

Commit 844da62

Browse files
Fix Explorer crash when Open-Shell exits while the menu is open (#2576)
CleanStartMenuDLL called CloseManagers() before CMenuContainer::CloseStartMenu(). When the start menu was still open at exit, destroying it ran CMenuContainer::OnDestroy -> g_SearchManager.CloseMenu(), which locks the search manager's critical section. CloseManagers had already deleted that lock, so Explorer crashed with an access violation in ntdll!RtlpWaitOnCriticalSection. This order dates back to at least the Classic Shell -> Open-Shell rebrand and is in 4.4.198 and current master. The menu, the settings window and the owner window are now closed before the managers are shut down. Found with a crash dump (WER LocalDumps + full page heap on explorer.exe): StartMenuDLL!CSearchManager::CloseMenu+0x2d (SearchManager.cpp:139) StartMenuDLL!CMenuContainer::OnDestroy+0x361 ... StartMenuDLL!CMenuContainer::CloseStartMenu+0xa0 StartMenuDLL!CleanStartMenuDLL+0x605 StartMenuDLL!HookDesktopThread+0x7e6 FAILURE_BUCKET_ID: NULL_CLASS_PTR_WRITE_AVRF_c0000005_StartMenuDLL.dll!CSearchManager::CloseMenu Reproduce: start StartMenu.exe, run "StartMenu.exe -open", and while the menu is visible run "StartMenu.exe -exit". Explorer restarts. Verified on Windows 11 (26100): unmodified master crashed Explorer in every run with the menu open at exit; with this change, 5 of 5 such runs exited cleanly.
1 parent 9dfa7fa commit 844da62

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

‎Src/StartMenu/StartMenuDLL/StartMenuDLL.cpp‎

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3314,14 +3314,17 @@ static void CleanStartMenuDLL( void )
33143314
ClearIatHook(g_ShellRegisterHotKeyHook);
33153315
g_ShellRegisterHotKeyHook=NULL;
33163316

3317-
CloseManagers(false);
3318-
ClearIatHooks();
3319-
3320-
// cleanup
3317+
// close the menu and the settings before the managers. an open menu calls g_SearchManager.CloseMenu() when it is destroyed,
3318+
// and after CloseManagers that would use the search manager's deleted lock and crash Explorer (exiting with the menu open)
33213319
if (g_Owner.m_hWnd) g_Owner.DestroyWindow();
33223320
CloseSettings();
33233321
CMenuContainer::CloseStartMenu();
33243322
CMenuFader::ClearAll();
3323+
3324+
CloseManagers(false);
3325+
ClearIatHooks();
3326+
3327+
// cleanup
33253328
UnhookDropTarget();
33263329
EnableHotkeys(HOTKEYS_CLEAR);
33273330
HWND hwnd=FindWindow(L"OpenShellMenu.CStartHookWindow",L"StartHookWindow");

0 commit comments

Comments
 (0)