# HG changeset patch # User bsmith@81767d24-ef19-dc11-ae90-00e081727c95 # Date 1340830231 0 # Node ID b472a892ce1fbd035d04a71e4025343987eb0641 # Parent ae7f1a0eb0eab429f08ecce869b12b345190bd2c Added code to plug several resource leaks on Windows. The GetIconInfo() leak is fixed but tooltips and bitmap buttons are still leaking fonts and icons respectively... even though I have verified the code to delete them is executing. diff -r ae7f1a0eb0ea -r b472a892ce1f win/dw.c --- a/win/dw.c Tue Jun 26 01:25:45 2012 +0000 +++ b/win/dw.c Wed Jun 27 20:50:31 2012 +0000 @@ -719,8 +719,8 @@ return 0L; } -/* This function removes and handlers on windows and frees - * the user memory allocated to it. +/* This function removes any handlers on windows and frees + * the user memory and resources allocated to it. */ BOOL CALLBACK _free_window_memory(HWND handle, LPARAM lParam) { @@ -728,7 +728,11 @@ HFONT oldfont = (HFONT)SendMessage(handle, WM_GETFONT, 0, 0); HICON oldicon = (HICON)SendMessage(handle, WM_GETICON, 0, 0); TCHAR tmpbuf[100] = {0}; - + HWND tooltip = (HWND)dw_window_get_data(handle, "_dw_tooltip"); + + if(tooltip) + DestroyWindow(tooltip); + GetClassName(handle, tmpbuf, 99); /* Don't try to free memory from an OLE embedded IE */ @@ -751,9 +755,12 @@ if(_tcsnicmp(tmpbuf, BUTTONCLASSNAME, _tcslen(BUTTONCLASSNAME)+1)==0) { HBITMAP oldbitmap = (HBITMAP)SendMessage(handle, BM_GETIMAGE, IMAGE_BITMAP, 0); + HICON oldicon = (HICON)SendMessage(handle, BM_GETIMAGE, IMAGE_ICON, 0); if(oldbitmap) DeleteObject(oldbitmap); + if(oldicon) + DestroyIcon(oldicon); } #ifdef TOOLBAR /* Bitmap Buttons */ @@ -4574,6 +4581,7 @@ static char testtext[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"; HBITMAP hbm = 0; HICON hic = 0; + ICONINFO ii = {0}; GetClassName(handle, tmpbuf, 99); @@ -4596,8 +4604,6 @@ /* If we got an icon, pull out the internal bitmap */ if(hic) { - ICONINFO ii; - if(GetIconInfo(hic, &ii)) hbm = ii.hbmMask ? ii.hbmMask : ii.hbmColor; } @@ -4840,6 +4846,12 @@ *width = thiswidth + extrawidth; if(height) *height = thisheight + extraheight; + + /* Free temporary bitmaps */ + if(ii.hbmColor) + DeleteObject(ii.hbmColor); + if(ii.hbmMask); + DeleteObject(ii.hbmMask); } /* @@ -6188,6 +6200,7 @@ return tmp; } +#ifdef TOOLBAR /* Internal function to create a grayscale bitmap from a color one */ void _to_grayscale(HBITMAP hbm, int width, int height) { @@ -6232,6 +6245,7 @@ dimlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32, 1, 0); _to_grayscale(hbitmap, bmi.bmWidth, bmi.bmHeight); ImageList_Add(dimlist, hbitmap, NULL); + DeleteObject(hbitmap); } else if(icon) { @@ -6244,6 +6258,9 @@ dimlist = ImageList_Create(bmi.bmWidth, bmi.bmHeight, ILC_COLOR32 | ILC_MASK, 1, 0); _to_grayscale(iconinfo.hbmColor, bmi.bmWidth, bmi.bmHeight); ImageList_Add(dimlist, iconinfo.hbmColor, iconinfo.hbmMask); + DeleteObject(iconinfo.hbmColor); + DeleteObject(iconinfo.hbmMask); + DestroyIcon(icon); } else return 0; @@ -6267,6 +6284,7 @@ _create_tooltip(tmp, text); return tmp; } +#endif /* * Create a new bitmap button window (widget) to be packed. @@ -9020,7 +9038,7 @@ */ void API dw_filesystem_set_column_title(HWND handle, char *title) { - char *newtitle = strdup(title ? title : ""); + char *newtitle = _strdup(title ? title : ""); dw_window_set_data(handle, "_dw_coltitle", newtitle); } @@ -11605,7 +11623,7 @@ memcpy(src, str, len); buf = UTF8toWide(src); free(src); - len = _tcslen(buf); + len = (int)_tcslen(buf); #else int type = CF_TEXT;