changeset 469:7952b9c1dc07

Free menu memory on Windows as well.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 08 Oct 2003 21:59:23 +0000
parents 0a2f13ba2d5c
children 6ccac112f1e5
files win/dw.c
diffstat 1 files changed, 31 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Wed Oct 08 21:40:06 2003 +0000
+++ b/win/dw.c	Wed Oct 08 21:59:23 2003 +0000
@@ -419,7 +419,21 @@
 
 void _free_menu_data(HMENU menu)
 {
-	/* TODO: This needs to call this on all submenus */
+#ifndef WINNT_COMPAT
+	int i, count = GetMenuItemCount(menu);
+
+	for(i=0;i<count;i++)
+	{
+		MENUITEMINFO mii;
+
+		mii.cbSize = sizeof(MENUITEMINFO);
+		mii.fMask = MIIM_SUBMENU;
+
+		if(GetMenuItemInfo(menu, i, TRUE, &mii)
+		   && mii.hSubMenu)
+			_free_menu_data(mii.hSubMenu);
+	}
+#endif
 	dw_signal_disconnect_by_name((HWND)menu, DW_SIGNAL_CLICKED);
 }
 
@@ -1873,9 +1887,16 @@
 		}
 		break;
 	case WM_DESTROY:
-		/* Free memory before destroying */
-		_free_window_memory(hWnd, 0);
-		EnumChildWindows(hWnd, _free_window_memory, 0);
+		{
+			HMENU menu = GetMenu(hWnd);
+
+			if(menu)
+				_free_menu_data(menu);
+
+			/* Free memory before destroying */
+			_free_window_memory(hWnd, 0);
+			EnumChildWindows(hWnd, _free_window_memory, 0);
+		}
 		break;
 	case WM_CTLCOLORSTATIC:
 	case WM_CTLCOLORLISTBOX:
@@ -3393,6 +3414,12 @@
 {
 	HWND parent = GetParent(handle);
 	Box *thisbox = (Box *)GetWindowLongPtr(parent, GWLP_USERDATA);
+#ifndef WINNT_COMPAT
+	HMENU menu = GetMenu(handle);
+
+	if(menu)
+		_free_menu_data(menu);
+#endif
 
 	if(parent != HWND_DESKTOP && thisbox && thisbox->count)
 	{