Skip to content

Commit

Permalink
[KBM] Fix for handle leak
Browse files Browse the repository at this point in the history
  • Loading branch information
enricogior committed May 10, 2021
1 parent d94919e commit f51d42d
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ KeyboardManager::KeyboardManager()
loadingSettings = false;
};

editorIsRunningEvent = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str());
settingsEventWaiter = EventWaiter(KeyboardManagerConstants::SettingsEventName, changeSettingsCallback);
}

Expand Down Expand Up @@ -127,8 +128,7 @@ intptr_t KeyboardManager::HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) n
}

// Suspend remapping if remap key/shortcut window is opened
auto h = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str());
if (h != nullptr && WaitForSingleObject(h, 0) == WAIT_OBJECT_0)
if (editorIsRunningEvent != nullptr && WaitForSingleObject(editorIsRunningEvent, 0) == WAIT_OBJECT_0)
{
return 0;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@ class KeyboardManager
// Constructor
KeyboardManager();

~KeyboardManager()
{
if (editorIsRunningEvent)
{
CloseHandle(editorIsRunningEvent);
}
}

void StartLowlevelKeyboardHook();
void StopLowlevelKeyboardHook();

Expand Down Expand Up @@ -43,6 +51,8 @@ class KeyboardManager
// Load settings from the file.
void LoadSettings();

HANDLE editorIsRunningEvent = nullptr;

// Function called by the hook procedure to handle the events. This is the starting point function for remapping
intptr_t HandleKeyboardHookEvent(LowlevelKeyboardEvent* data) noexcept;
};

0 comments on commit f51d42d

Please sign in to comment.