From 2f9a90f88ef9052b306cb7efd12dd1111324eb29 Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Mon, 27 Sep 2021 20:45:56 +0300 Subject: [PATCH] Fix GUI GDI leak --- od-win32/win32gui_extra.cpp | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/od-win32/win32gui_extra.cpp b/od-win32/win32gui_extra.cpp index 35f24191..231dd874 100644 --- a/od-win32/win32gui_extra.cpp +++ b/od-win32/win32gui_extra.cpp @@ -751,15 +751,28 @@ void x_DestroyWindow(HWND hwnd, struct newresource *res) for (int i = 0; res->hwndcnt; i++) { struct newreswnd *pr = &res->hwnds[i]; if (res->hwnds[i].hwnd == hwnd) { - res->hwndcnt--; - int tomove = res->hwndcnt - i; - if (tomove > 0) { - memmove(&res->hwnds[i], &res->hwnds[i + 1], tomove * sizeof(newreswnd)); + while (i + 1 < res->hwndcnt) { + res->hwnds[i] = res->hwnds[i + 1]; + i++; } + res->hwndcnt--; + res->hwnds[res->hwndcnt].hwnd = NULL; + res->hwnds[res->hwndcnt].x = res->hwnds[res->hwndcnt].y = res->hwnds[res->hwndcnt].w = res->hwnds[res->hwndcnt].h = 0; break; } } DestroyWindow(hwnd); + if (res->child) { + struct newresource *cres = res->child; + if (cres->dinfo.hUserFont) { + DeleteObject(cres->dinfo.hUserFont); + cres->dinfo.hUserFont = NULL; + } + if (cres->dinfo.hMenu) { + DeleteObject(cres->dinfo.hMenu); + cres->dinfo.hMenu = NULL; + } + } } static int align (double f) -- 2.47.3