From e5ac4db667ccfd3e33892bef3706cfcaea65c257 Mon Sep 17 00:00:00 2001 From: Tim Abraldes Date: Thu, 5 Jul 2012 16:06:13 -0700 Subject: [PATCH] bug 708033. Cache the large and small icons that are set for each `nsWindow`. Free them in `nsWindow::~nsWindow()` rather than in `nsWindow::OnDestroy()`. r=jimm --- widget/windows/nsWindow.cpp | 20 +++++++++++--------- widget/windows/nsWindow.h | 2 ++ 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/widget/windows/nsWindow.cpp b/widget/windows/nsWindow.cpp index cde60247cfa..db1c0334059 100644 --- a/widget/windows/nsWindow.cpp +++ b/widget/windows/nsWindow.cpp @@ -308,6 +308,8 @@ nsWindow::nsWindow() : nsBaseWidget() } #endif + mIconSmall = nsnull; + mIconBig = nsnull; mWnd = nsnull; mPaintDC = nsnull; mPrevWndProc = nsnull; @@ -390,6 +392,13 @@ nsWindow::~nsWindow() if (NULL != mWnd) Destroy(); + // Free app icon resources. This must happen after `OnDestroy` (see bug 708033). + if (mIconSmall) + ::DestroyIcon(mIconSmall); + + if (mIconBig) + ::DestroyIcon(mIconBig); + sInstanceCount--; // Global shutdown @@ -2824,6 +2833,7 @@ NS_METHOD nsWindow::SetIcon(const nsAString& aIconSpec) HICON icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM)bigIcon); if (icon) ::DestroyIcon(icon); + mIconBig = bigIcon; } #ifdef DEBUG_SetIcon else { @@ -2837,6 +2847,7 @@ NS_METHOD nsWindow::SetIcon(const nsAString& aIconSpec) HICON icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM)smallIcon); if (icon) ::DestroyIcon(icon); + mIconSmall = smallIcon; } #ifdef DEBUG_SetIcon else { @@ -6945,15 +6956,6 @@ void nsWindow::OnDestroy() mBrush = NULL; } - // Free app icon resources. - HICON icon; - icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_BIG, (LPARAM) 0); - if (icon) - ::DestroyIcon(icon); - - icon = (HICON) ::SendMessageW(mWnd, WM_SETICON, (WPARAM)ICON_SMALL, (LPARAM) 0); - if (icon) - ::DestroyIcon(icon); // Destroy any custom cursor resources. if (mCursor == -1) diff --git a/widget/windows/nsWindow.h b/widget/windows/nsWindow.h index ae1951f74ca..fae2dccecf4 100644 --- a/widget/windows/nsWindow.h +++ b/widget/windows/nsWindow.h @@ -481,6 +481,8 @@ protected: WindowHook mWindowHook; DWORD mAssumeWheelIsZoomUntil; PRUint32 mPickerDisplayCount; + HICON mIconSmall; + HICON mIconBig; static bool sDropShadowEnabled; static PRUint32 sInstanceCount; static TriStateBool sCanQuit;