From f239823e9afd27ab0ecf28e1d567831e3c62a25e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Sun, 23 Aug 2026 12:21:31 +0200 Subject: [PATCH] Platform: fix a handle leak in Windows-specific DPI scaling code. Rather unlikely to be hit in practice because the default is virtual DPI scaling and this is just a fallback, but still. --- src/Magnum/Platform/Sdl2Application.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Magnum/Platform/Sdl2Application.cpp b/src/Magnum/Platform/Sdl2Application.cpp index 0c146e72b..a997ca45f 100644 --- a/src/Magnum/Platform/Sdl2Application.cpp +++ b/src/Magnum/Platform/Sdl2Application.cpp @@ -418,6 +418,9 @@ Vector2 Sdl2Application::dpiScalingInternal(const Implementation::Sdl2DpiScaling #elif defined(CORRADE_TARGET_WINDOWS) && !defined(CORRADE_TARGET_WINDOWS_RT) HDC hDC = GetWindowDC(nullptr); Vector2i monitorSize{GetDeviceCaps(hDC, HORZSIZE), GetDeviceCaps(hDC, VERTSIZE)}; + /* The handle is apparently allocated anew each time, so we have to release + it back: https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-getwindowdc#remarks */ + ReleaseDC(nullptr, hDC); SDL_DisplayMode mode; CORRADE_INTERNAL_ASSERT(SDL_GetDesktopDisplayMode(0, &mode) == 0); auto dpi = Vector2{Vector2i{mode.w, mode.h}*25.4f/Vector2{monitorSize}};