From: Julian Smart Date: Mon, 9 Dec 2002 09:29:00 +0000 (+0000) Subject: Applied patch [ 642157 ] [MSW] HMENU resource leak from wxMenuBar X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/7a0363dd04205d701f82912adac40453995636ef Applied patch [ 642157 ] [MSW] HMENU resource leak from wxMenuBar 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 --- diff --git a/src/msw/menu.cpp b/src/msw/menu.cpp index eb78604c7d..6420604cc5 100644 --- a/src/msw/menu.cpp +++ b/src/msw/menu.cpp @@ -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(); }