From 617b7adb09adf8171b2b127066840ab08b23be07 Mon Sep 17 00:00:00 2001 From: Enrico Giordani Date: Mon, 10 May 2021 01:39:54 -0700 Subject: [PATCH] [KBM] Fix for handle leak (#11182) --- .../KeyboardManagerEngineLibrary/KeyboardManager.cpp | 4 ++-- .../KeyboardManagerEngineLibrary/KeyboardManager.h | 12 +++++++++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.cpp b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.cpp index 953ba23afe..83369f2e32 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.cpp +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.cpp @@ -50,6 +50,7 @@ KeyboardManager::KeyboardManager() loadingSettings = false; }; + editorIsRunningEvent = CreateEvent(nullptr, true, false, KeyboardManagerConstants::EditorWindowEventName.c_str()); settingsEventWaiter = EventWaiter(KeyboardManagerConstants::SettingsEventName, changeSettingsCallback); } @@ -126,8 +127,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; } diff --git a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.h b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.h index af30fae587..457a9135b7 100644 --- a/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.h +++ b/src/modules/keyboardmanager/KeyboardManagerEngineLibrary/KeyboardManager.h @@ -9,7 +9,15 @@ class KeyboardManager public: // Constructor KeyboardManager(); - + + ~KeyboardManager() + { + if (editorIsRunningEvent) + { + CloseHandle(editorIsRunningEvent); + } + } + void StartLowlevelKeyboardHook(); void StopLowlevelKeyboardHook(); @@ -38,6 +46,8 @@ private: std::atomic_bool loadingSettings = false; + HANDLE editorIsRunningEvent = nullptr; + // Hook procedure definition static LRESULT CALLBACK HookProc(int nCode, WPARAM wParam, LPARAM lParam);