From d976d9eb0cc483e6dfda12bba799c065934cb87f Mon Sep 17 00:00:00 2001 From: Fernando Marino` Date: Sun, 27 Sep 2026 13:19:27 +0200 Subject: [PATCH] Release the DC after GetDC in get_dpi_for_window and font enumeration (#15919) get_dpi_for_window's pre-8.1 fallback and get_font_list_by_enumeration both called GetDC without a matching ReleaseDC, leaking a GDI handle each call. get_dpi_for_window runs on every mouse-move over the 3D viewport, so the leak exhausts the per-process GDI handle limit and hangs the app within minutes on Windows 7/8. Co-authored-by: Fernando Marino Co-authored-by: Claude Sonnet 5 --- src/libslic3r/Emboss.cpp | 1 + src/slic3r/GUI/GUI_Utils.cpp | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/libslic3r/Emboss.cpp b/src/libslic3r/Emboss.cpp index 34d9a93590..38c035806c 100644 --- a/src/libslic3r/Emboss.cpp +++ b/src/libslic3r/Emboss.cpp @@ -990,6 +990,7 @@ EmbossStyles Emboss::get_font_list_by_enumeration() { std::vector font_names; EnumFontFamilies(hDC, (LPCTSTR) NULL, EnumFamCallBack, (LPARAM) &font_names); + ReleaseDC(NULL, hDC); EmbossStyles font_list; for (const std::wstring &font_name : font_names) { diff --git a/src/slic3r/GUI/GUI_Utils.cpp b/src/slic3r/GUI/GUI_Utils.cpp index 10dd29c9c1..5c55e341c9 100644 --- a/src/slic3r/GUI/GUI_Utils.cpp +++ b/src/slic3r/GUI/GUI_Utils.cpp @@ -247,7 +247,9 @@ int get_dpi_for_window(const wxWindow *window) const HDC hdc = GetDC(hwnd); if (hdc == NULL) { return DPI_DEFAULT; } - return GetDeviceCaps(hdc, LOGPIXELSX); + const int dpi = GetDeviceCaps(hdc, LOGPIXELSX); + ReleaseDC(hwnd, hdc); // GetDC's handle must be released, unlike GetWindowDC's + return dpi; } #elif defined __linux__ // TODO