Skip to content

Commit

Permalink
Don't leak timer handles
Browse files Browse the repository at this point in the history
  • Loading branch information
fredemmott committed Jan 4, 2024
1 parent f7c0a95 commit b23cc22
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions lib/EventLoop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
* in the root directory of this source tree.
*/
#include <cpp-remapper/EventLoop.h>

#include <cpp-remapper/EventSink.h>
#include <cpp-remapper/EventSource.h>
#include <cpp-remapper/InputDevice.h>
Expand All @@ -15,7 +14,7 @@ namespace fredemmott::inputmapping {

namespace {

HANDLE gExitEvent;
HANDLE gExitEvent {};
BOOL WINAPI exit_event_handler(DWORD dwCtrlType) {
SetEvent(gExitEvent);
return true;
Expand Down Expand Up @@ -134,6 +133,9 @@ void EventLoop::inject(
auto timer = CreateWaitableTimer(nullptr, true, nullptr);
SetWaitableTimer(
timer, (LARGE_INTEGER*)&target_time, 0, nullptr, nullptr, false);
gActiveInstance->mInjected.emplace(timer, handler);
gActiveInstance->mInjected.emplace(timer, [handler, timer]() {
CloseHandle(timer);
handler();
});
}
}// namespace fredemmott::inputmapping

0 comments on commit b23cc22

Please sign in to comment.