From 9f91bd6ea92d23f87ce301511f69c329494126b0 Mon Sep 17 00:00:00 2001 From: przemekmirek Date: Thu, 4 Jan 2018 20:45:55 +0100 Subject: [PATCH] Win32: Fix HDEVNOTIFY handle leak Closes #1170. --- src/win32_init.c | 10 +++++++--- src/win32_platform.h | 1 + 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/win32_init.c b/src/win32_init.c index ee7ccfda..a913846d 100644 --- a/src/win32_init.c +++ b/src/win32_init.c @@ -351,9 +351,10 @@ static HWND createHelperWindow(void) dbi.dbcc_devicetype = DBT_DEVTYP_DEVICEINTERFACE; dbi.dbcc_classguid = GUID_DEVINTERFACE_HID; - RegisterDeviceNotificationW(window, - (DEV_BROADCAST_HDR*) &dbi, - DEVICE_NOTIFY_WINDOW_HANDLE); + _glfw.win32.deviceNotificationHandle = + RegisterDeviceNotificationW(window, + (DEV_BROADCAST_HDR*) &dbi, + DEVICE_NOTIFY_WINDOW_HANDLE); } while (PeekMessageW(&msg, _glfw.win32.helperWindowHandle, 0, 0, PM_REMOVE)) @@ -543,6 +544,9 @@ int _glfwPlatformInit(void) void _glfwPlatformTerminate(void) { + if (_glfw.win32.deviceNotificationHandle) + UnregisterDeviceNotification(_glfw.win32.deviceNotificationHandle); + if (_glfw.win32.helperWindowHandle) DestroyWindow(_glfw.win32.helperWindowHandle); diff --git a/src/win32_platform.h b/src/win32_platform.h index 73bcb49b..958a3137 100644 --- a/src/win32_platform.h +++ b/src/win32_platform.h @@ -288,6 +288,7 @@ typedef struct _GLFWwindowWin32 typedef struct _GLFWlibraryWin32 { HWND helperWindowHandle; + HDEVNOTIFY deviceNotificationHandle; DWORD foregroundLockTimeout; int acquiredMonitorCount; char* clipboardString;