Destroy window icons to avoid memory leaks

This commit is contained in:
Ioannis Tsakpinis 2015-09-07 16:04:59 +03:00
parent 1b51ef3d0e
commit 9abfe97937

View File

@ -722,8 +722,18 @@ static void destroyWindow(_GLFWwindow* window)
if (window->win32.handle) if (window->win32.handle)
{ {
HICON iconBig = (HICON)SendMessage(window->win32.handle, WM_GETICON, ICON_BIG, 0);
HICON iconSmall = (HICON)SendMessage(window->win32.handle, WM_GETICON, ICON_SMALL, 0);
DestroyWindow(window->win32.handle); DestroyWindow(window->win32.handle);
window->win32.handle = NULL; window->win32.handle = NULL;
if (iconBig) // Destroy icon(s)
{
DestroyIcon(iconBig);
if (iconSmall != iconBig)
DestroyIcon(iconSmall);
}
} }
} }
@ -1047,8 +1057,15 @@ void _glfwPlatformSetWindowIcons(_GLFWwindow* window, GLFWimage* icons, int coun
imgSmall = bestFit(icons, count, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON)); imgSmall = bestFit(icons, count, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON));
HICON icon = createIcon(imgBig); HICON icon = createIcon(imgBig);
SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) icon); HICON iconBig = (HICON)SendMessage(window->win32.handle, WM_SETICON, ICON_BIG, (LPARAM) icon);
SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) (imgSmall == imgBig ? icon : createIcon(imgSmall))); HICON iconSmall = (HICON)SendMessage(window->win32.handle, WM_SETICON, ICON_SMALL, (LPARAM) (imgSmall == imgBig ? icon : createIcon(imgSmall)));
if (iconBig) // Destroy previous icon(s)
{
DestroyIcon(iconBig);
if (iconSmall != iconBig)
DestroyIcon(iconSmall);
}
} }
void _glfwPlatformIconifyWindow(_GLFWwindow* window) void _glfwPlatformIconifyWindow(_GLFWwindow* window)