]> git.unchartedbackwaters.co.uk Git - francis/winuae.git/commitdiff
Fix GUI GDI leak
authorToni Wilen <twilen@winuae.net>
Mon, 27 Sep 2021 17:45:56 +0000 (20:45 +0300)
committerToni Wilen <twilen@winuae.net>
Mon, 27 Sep 2021 17:45:56 +0000 (20:45 +0300)
od-win32/win32gui_extra.cpp

index 35f24191162249c9dc9bd6864fd81013bab400ec..231dd87480b35d5c30752b593bec16c2dc0a00fb 100644 (file)
@@ -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)