Repository navigation
Fix silent startup deadlock on Windows 11 due to premature FreeLibrary - #1155
Merged
sabrogden merged 2 commits intoSep 22, 2026
Merged
Conversation
In CPowerManager::Start, powrprof.dll was loaded, PowerRegisterSuspendResumeNotification was called, and ::FreeLibrary(powrprof) was immediately invoked. On modern Windows 11 builds, calling FreeLibrary on powrprof.dll while a suspend/resume notification callback is active causes powrprof to invoke UMPDC.dll, which executes WaitForSingleObjectEx during DLL unload under the loader lock, deadlocking the main UI thread synchronously during CMainFrame::OnCreate. As a result, Ditto hangs permanently on startup without creating its systray icon or showing any windows. In addition, PowerUnregisterSuspendResumeNotification takes HPOWERNOTIFY by value, not by pointer. This fix: 1. Retains HMODULE m_hPowrProf as a member of CPowerManager across the application lifetime. 2. Keeps powrprof.dll loaded while notifications are registered. 3. Corrects the function signature and invocation for PowerUnregisterSuspendResumeNotification. 4. Safely unregisters notifications and frees powrprof.dll only during CPowerManager::Close().
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
Unregister failures are ignored, allowing the module to be unloaded while notifications may remain registered.
Get a fresh assessment by requesting another Copilot review.
Review effort: Lite
Findings: 1
What changed in this PR
Fixes a Windows startup deadlock by retaining powrprof.dll while power notifications are registered and correcting notification cleanup.
Changes:
- Retains the DLL handle across the manager lifecycle.
- Corrects notification unregistration usage.
- Defers unregistering and unloading until shutdown.
| File | Description |
|---|---|
src/PowerManager.h |
Adds persistent power-management DLL state and updates cleanup declarations. |
src/PowerManager.cpp |
Updates DLL loading, notification registration, unregistration, and cleanup. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Comment on lines
+75
to
+80
| PowerUnregisterSuspendResumeNotification(m_registrationHandle); | ||
| } | ||
|
|
||
| ::FreeLibrary(powrprof); | ||
| m_registrationHandle = 0; | ||
| } | ||
|
|
||
| ::FreeLibrary(m_hPowrProf); |
sabrogden
approved these changes
Sep 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

In CPowerManager::Start, powrprof.dll was loaded, PowerRegisterSuspendResumeNotification was called, and ::FreeLibrary(powrprof) was immediately invoked.
On modern Windows 11 builds, calling FreeLibrary on powrprof.dll while a suspend/resume notification callback is active causes powrprof to invoke UMPDC.dll, which executes WaitForSingleObjectEx during DLL unload under the loader lock, deadlocking the main UI thread synchronously during CMainFrame::OnCreate. As a result, Ditto hangs permanently on startup without creating its systray icon or showing any windows.
In addition, PowerUnregisterSuspendResumeNotification takes HPOWERNOTIFY by value, not by pointer.
This fix:
Windows 11 Pro for Workstations Insider Preview
Dev 29634.1000