Skip to content

Commit

Permalink
* Fix resource leaks in ProfilePopout
Browse files Browse the repository at this point in the history
  • Loading branch information
iProgramMC committed Sep 21, 2024
1 parent 224e2ac commit 32fd5b2
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions src/windows/ProfilePopout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ bool ProfilePopout::Layout(HWND hWnd, SIZE& fullSize)
if (hbm) {
hdc = GetDC(hWnd);
int pps = GetProfilePictureSize();
m_hBitmap = ResizeWithBackgroundColor(
HBITMAP hnewbm = ResizeWithBackgroundColor(
hdc,
hbm,
GetSysColorBrush(COLOR_3DFACE),
Expand All @@ -334,7 +334,8 @@ bool ProfilePopout::Layout(HWND hWnd, SIZE& fullSize)
);
ReleaseDC(hWnd, hdc);
ShowWindow(hChild, SW_SHOW);
SendMessage(hChild, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM)m_hBitmap);
HBITMAP holdbm = (HBITMAP) SendMessage(hChild, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) hnewbm);
if (holdbm) DeleteBitmap(holdbm);
}
hChild = GetDlgItem(hWnd, IDC_GUILD_JOIN_DATE);
ShowWindow(hChild, SW_SHOW);
Expand All @@ -351,14 +352,14 @@ bool ProfilePopout::Layout(HWND hWnd, SIZE& fullSize)

if (rcMemberSinceDiscord.bottom) {
int icsz = GetSystemMetrics(SM_CXSMICON);
if (icsz <= 16) icsz = 16; // ensure a common size so LoadImage wont leak our LR_SHARED loaded icon
else if (icsz <= 32) icsz = 32;
else if (icsz <= 48) icsz = 48;
else icsz = 64;
hChild = GetDlgItem(hWnd, IDC_ICON_DISCORD);
ShowWindow(hChild, SW_SHOW);
MoveWindow(hChild, pos.x, pos.y, joinedAtIconSize, joinedAtIconSize, TRUE);
SendMessage(hChild, STM_SETIMAGE, IMAGE_ICON, (LPARAM) LoadImage(g_hInstance, MAKEINTRESOURCE(DMIC(IDI_ICON)), IMAGE_ICON, icsz, icsz, LR_SHARED | LR_CREATEDIBSECTION));

// note: the old icon may have been set by the dialog itself.
HICON hic = (HICON) SendMessage(hChild, STM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadImage(g_hInstance, MAKEINTRESOURCE(DMIC(IDI_ICON)), IMAGE_ICON, icsz, icsz, LR_CREATEDIBSECTION));
if (hic) DestroyIcon(hic);

hChild = GetDlgItem(hWnd, IDC_DISCORD_JOIN_DATE);
ShowWindow(hChild, SW_SHOW);
SetWindowText(hChild, dscJoinedAt);
Expand Down Expand Up @@ -509,18 +510,28 @@ BOOL CALLBACK ProfilePopout::Proc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lP
return res;
}

case WM_DESTROY:
case WM_DESTROY: {
FlushNote();

HWND hMSDIcon = GetDlgItem(hWnd, IDC_ICON_DISCORD);
HWND hMSGIcon = GetDlgItem(hWnd, IDC_ICON_GUILD);
HICON hic = (HICON) SendMessage(hMSDIcon, STM_SETIMAGE, IMAGE_ICON, (LPARAM) NULL);
if (hic)
DestroyIcon(hic); // the icon was loaded without LR_SHARED
HBITMAP hbm = (HBITMAP) SendMessage(hMSGIcon, STM_SETIMAGE, IMAGE_BITMAP, (LPARAM) NULL);
if (hbm)
DeleteBitmap(hbm);

m_hwnd = NULL;
SAFE_DELETE(m_pRoleList);
SAFE_DELETE(m_pProfileView);

if (m_hBitmap) {
DeleteBitmap(m_hBitmap);
//DeleteBitmap(m_hBitmap);
m_hBitmap = NULL;
}
return TRUE;
}
}

return FALSE;
Expand Down

0 comments on commit 32fd5b2

Please sign in to comment.