]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied patch [ 642157 ] [MSW] HMENU resource leak from wxMenuBar
authorJulian Smart <julian@anthemion.co.uk>
Mon, 9 Dec 2002 09:29:00 +0000 (09:29 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Mon, 9 Dec 2002 09:29:00 +0000 (09:29 +0000)
Latest CVS - When a wxMenuBar is detached
from a frame and deleted the HMENU resource leaks.
This patch fixes the leak.

Scott Pleiter

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@18128 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/menu.cpp

index eb78604c7d7cfed7d21b6981b0dae88a17bd0116..6420604cc5800090481a136099387e55d7dc450b 100644 (file)
@@ -557,6 +557,13 @@ wxMenuBar::wxMenuBar(int count, wxMenu *menus[], const wxString titles[])
 
 wxMenuBar::~wxMenuBar()
 {
+    // we should free Windows resources only if Windows doesn't do it for us
+    // which happens if we're attached to a frame
+    if (m_hMenu && !IsAttached())
+    {
+        ::DestroyMenu((HMENU)m_hMenu);
+        m_hMenu = (WXHMENU)NULL;
+    }
 }
 
 // ---------------------------------------------------------------------------
@@ -838,8 +845,6 @@ void wxMenuBar::Attach(wxFrame *frame)
 
 void wxMenuBar::Detach()
 {
-    m_hMenu = (WXHMENU)NULL;
-
     wxMenuBarBase::Detach();
 }