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 <f.marino@rheagroup.com>
Co-authored-by: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Fernando Marino`
2026-09-27 14:19:27 +03:00
committed by GitHub
co-authored by Fernando Marino Claude Sonnet 5
parent ae27a795b6
commit d976d9eb0c
2 changed files with 4 additions and 1 deletions
+1
View File
@@ -990,6 +990,7 @@ EmbossStyles Emboss::get_font_list_by_enumeration() {
std::vector<std::wstring> font_names;
EnumFontFamilies(hDC, (LPCTSTR) NULL, EnumFamCallBack,
(LPARAM) &font_names);
ReleaseDC(NULL, hDC);
EmbossStyles font_list;
for (const std::wstring &font_name : font_names) {
+3 -1
View File
@@ -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