Skip to content

Commit

Permalink
fix ResToText handle leaks
Browse files Browse the repository at this point in the history
  • Loading branch information
katahiromz committed Feb 9, 2025
1 parent ea9da8b commit 07afbb8
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
1 change: 0 additions & 1 deletion MyWndCtrl/MWindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1034,7 +1034,6 @@ inline void MZCAPI FillBitmapDx(HBITMAP hbm, HBRUSH hbr)
RECT rc;
SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
FillRect(hDC, &rc, hbr);
DeleteObject(hbr);
}
SelectObject(hDC, hbmOld);
}
Expand Down
1 change: 0 additions & 1 deletion src/MWindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,6 @@ inline void MZCAPI FillBitmapDx(HBITMAP hbm, HBRUSH hbr)
RECT rc;
SetRect(&rc, 0, 0, bm.bmWidth, bm.bmHeight);
FillRect(hDC, &rc, hbr);
DeleteObject(hbr);
}
SelectObject(hDC, hbmOld);
}
Expand Down
20 changes: 14 additions & 6 deletions src/ResToText.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1300,15 +1300,16 @@ CreateBitmapFromIconDx(HICON hIcon, INT width, INT height, BOOL bCursor)
assert(0);
return NULL;
}
FillBitmapDx(hbm, GetStockBrush(LTGRAY_BRUSH));
HBRUSH hbr = GetStockBrush(LTGRAY_BRUSH);
FillBitmapDx(hbm, hbr);

HDC hDC = CreateCompatibleDC(NULL);
HGDIOBJ hbmOld = SelectObject(hDC, hbm);
{
HBRUSH hbr = GetStockBrush(LTGRAY_BRUSH);
DrawIconEx(hDC, 0, 0, hIcon, width, height, 0, hbr, DI_NORMAL);
}
SelectObject(hDC, hbmOld);
DeleteObject(hbr);
DeleteDC(hDC);

return hbm;
Expand Down Expand Up @@ -1556,8 +1557,11 @@ CreateBitmapFromIconsDx(HWND hwnd, const EntryBase& entry)
assert(0);
return NULL;
}
FillBitmapDx(hbm, GetStockBrush(LTGRAY_BRUSH));


HBRUSH hbr = GetStockBrush(LTGRAY_BRUSH);
FillBitmapDx(hbm, hbr);
DeleteObject(hbr);

BITMAP bm;
GetObject(hbm, sizeof(bm), &bm);

Expand All @@ -1577,8 +1581,9 @@ CreateBitmapFromIconsDx(HWND hwnd, const EntryBase& entry)
auto icon_entry = (EntryBase&)*e;

HBITMAP hbmIcon = CreateBitmapFromIconOrPngDx(hwnd, icon_entry, bm);

DrawBitmapDx(hbm, hbmIcon, 0, y);
DeleteObject(hbmIcon);

y += bm.bmHeight;
}

Expand Down Expand Up @@ -1662,7 +1667,10 @@ CreateBitmapFromCursorsDx(HWND hwnd, const EntryBase& entry)
assert(0);
return NULL;
}
FillBitmapDx(hbm, GetStockBrush(LTGRAY_BRUSH));

HBRUSH hbr = GetStockBrush(LTGRAY_BRUSH);
FillBitmapDx(hbm, hbr);
DeleteObject(hbr);

HDC hDC = CreateCompatibleDC(NULL);
HDC hDC2 = CreateCompatibleDC(NULL);
Expand Down

0 comments on commit 07afbb8

Please sign in to comment.