[commit] r2059 - trunk/GME/Gme

GMESRC Repository Notifications gme-commit at list.isis.vanderbilt.edu
Wed Sep 19 17:49:22 CDT 2012


Author: ksmyth
Date: Wed Sep 19 17:49:21 2012
New Revision: 2059

Log:
Fix some resource leaks that could result in the dreaded "Encountered an invalid argument" MessageBox

Modified:
   trunk/GME/Gme/ChildFrm.cpp
   trunk/GME/Gme/ChildFrm.h
   trunk/GME/Gme/MainFrm.cpp
   trunk/GME/Gme/ModelPropertiesDlgBar.cpp
   trunk/GME/Gme/ModelPropertiesDlgBar.h

Modified: trunk/GME/Gme/ChildFrm.cpp
==============================================================================
--- trunk/GME/Gme/ChildFrm.cpp	Wed Sep 19 17:49:07 2012	(r2058)
+++ trunk/GME/Gme/ChildFrm.cpp	Wed Sep 19 17:49:21 2012	(r2059)
@@ -144,12 +144,15 @@
 	sendEvent = true;
 
 	if(doClose)
+		// CFramewWnd::OnClose calls CMDIChildWnd::DestroyWindow
 		CMDIChildWndEx::OnClose();
 
 	// CMDIChildWndEx::OnClose: when the last ChildWnd is closed
 	// the document is considered closed and the title changes to Paradigm
 	// that's why we call this:
 	theApp.UpdateMainTitle();
+
+// 	DestroyWindow();
 }
 
 void CChildFrame::OnSize(UINT nType, int cx, int cy)

Modified: trunk/GME/Gme/ChildFrm.h
==============================================================================
--- trunk/GME/Gme/ChildFrm.h	Wed Sep 19 17:49:07 2012	(r2058)
+++ trunk/GME/Gme/ChildFrm.h	Wed Sep 19 17:49:21 2012	(r2059)
@@ -65,6 +65,46 @@
 	afx_msg void OnUpdateFrameTitle(BOOL bAddToTitle);
 	virtual BOOL PreTranslateMessage(MSG* pMsg);
 	virtual void RegisterTaskbarTab(CMDIChildWndEx* pWndBefore = NULL) { } // disable each tab showing up on the taskbar in windows 7
+
+	afx_msg void PostNcDestroy() {
+		delete this;
+	}
+
+	BOOL Create(LPCTSTR lpszClassName,
+		LPCTSTR lpszWindowName, DWORD dwStyle,
+		const RECT& rect, CMDIFrameWnd* pParentWnd,
+		CCreateContext* pContext)
+	{
+	/* n.b. modifying style fixes a menu leak:
+	Function tag: 0x49 (LoadMenuW)
+	Cleanup tag: 0x6a (DestroyMenu)
+	0x75a1a655      USER32!xxxLoadSysMenu+0x1a
+	0x75a1a607      USER32!CreateMDIChild+0xa3
+	0x75a1a2bf      USER32!_CreateWindowEx+0xfe
+	0x75a08a5c      USER32!CreateWindowExW+0x33
+	0x10009b12      LeakTrap_vc71!detail::MyCreateWindowExW+0x42
+	0x75a1c9d0      USER32!MDIClientWndProcWorker+0x42c
+	0x75a18585      USER32!MDIClientWndProcW+0x29
+	0x75a062fa      USER32!InternalCallWinProc+0x23
+	0x75a06d3a      USER32!UserCallWinProcCheckWow+0x109
+	0x75a10d27      USER32!CallWindowProcAorW+0xab
+	0x75a10d4d      USER32!CallWindowProcW+0x1b
+	0x5b363b50      mfc100u!CWnd::DefWindowProcW+0x44
+	0x5b364bc4      mfc100u!CWnd::WindowProc+0x3b
+	0x5b362fcc      mfc100u!AfxCallWndProc+0xb5
+	0x5b363258      mfc100u!AfxWndProc+0x37
+	0x5b259faf      mfc100u!AfxWndProcBase+0x56
+	0x75a062fa      USER32!InternalCallWinProc+0x23
+	0x75a06d3a      USER32!UserCallWinProcCheckWow+0x109
+	0x75a0965e      USER32!SendMessageWorker+0x581
+	0x75a096c5      USER32!SendMessageW+0x7f
+	0x5b3780a8      mfc100u!CMDIChildWnd::Create+0x103
+	0x5b3781e4      mfc100u!CMDIChildWnd::LoadFrame+0xb9
+	0x5b31a4b9      mfc100u!CDocTemplate::CreateNewFrame+0x60
+	0x4e2cfc        GME!CMainFrame::CreateNewView+0x5c
+	*/
+		return __super::Create(lpszClassName, lpszWindowName, dwStyle & ~WS_SYSMENU, rect, pParentWnd, pContext);
+	}
 };
 
 /////////////////////////////////////////////////////////////////////////////

Modified: trunk/GME/Gme/MainFrm.cpp
==============================================================================
--- trunk/GME/Gme/MainFrm.cpp	Wed Sep 19 17:49:07 2012	(r2058)
+++ trunk/GME/Gme/MainFrm.cpp	Wed Sep 19 17:49:21 2012	(r2059)
@@ -660,6 +660,18 @@
 		frame->ActivateFrame(frame->IsIconic() ? SW_SHOWNORMAL : -1);
 }
 
+struct AccessProtectedKludge : public CMDIClientAreaWnd 
+{
+	CObList& get()
+	{
+		return m_lstRemovedTabbedGroups;
+	}
+	static CObList& get(CMDIClientAreaWnd& clientarea)
+	{
+		return ((AccessProtectedKludge*)(&clientarea))->get();
+	}
+};
+
 void CMainFrame::CreateNewView(CView *view, CComPtr<IMgaModel>& model)
 {
 	CMultiDocTemplate *docTemplate = theApp.pDocTemplate;
@@ -686,6 +698,20 @@
 		m_wndClientArea.UpdateMDITabbedGroups(FALSE);  // The framework by default calls this via OnUpdateFrameTitle 
 		                                              // (overloaded in our implementation without calling the base class intentionally)
 
+		// n.b. m_wndClientArea is long-lived, but puts closed tab groups in .m_lstRemovedTabbedGroups
+		// delete them here to prevent a resource leak
+		// FIXME: this should run when the last tab is closed
+		CObList& m_lstRemovedTabbedGroups = AccessProtectedKludge::get(m_wndClientArea);
+		while (!m_lstRemovedTabbedGroups.IsEmpty())
+		{
+			CMFCTabCtrl* pWnd= DYNAMIC_DOWNCAST(CMFCTabCtrl, m_lstRemovedTabbedGroups.RemoveTail());
+			if (pWnd != NULL)
+			{
+				pWnd->DestroyWindow();
+				delete pWnd;
+			}
+		}
+
 		CGMEView* newGmeview = CGMEView::GetActiveView();
 
 		if (oldGmeview)

Modified: trunk/GME/Gme/ModelPropertiesDlgBar.cpp
==============================================================================
--- trunk/GME/Gme/ModelPropertiesDlgBar.cpp	Wed Sep 19 17:49:07 2012	(r2058)
+++ trunk/GME/Gme/ModelPropertiesDlgBar.cpp	Wed Sep 19 17:49:21 2012	(r2059)
@@ -15,6 +15,9 @@
 /////////////////////////////////////////////////////////////////////////////
 // CModelPropertiesDlgBar dialog
 
+IMPLEMENT_DYNCREATE(CModelPropertiesDlgBar, CPaneDialog)
+
+
 CModelPropertiesDlgBar::CModelPropertiesDlgBar()
 : CPaneDialog()
 {

Modified: trunk/GME/Gme/ModelPropertiesDlgBar.h
==============================================================================
--- trunk/GME/Gme/ModelPropertiesDlgBar.h	Wed Sep 19 17:49:07 2012	(r2058)
+++ trunk/GME/Gme/ModelPropertiesDlgBar.h	Wed Sep 19 17:49:21 2012	(r2059)
@@ -14,6 +14,7 @@
 
 class CModelPropertiesDlgBar : public CPaneDialog
 {
+	DECLARE_DYNCREATE(CModelPropertiesDlgBar)
 // Construction
 public:
 	CModelPropertiesDlgBar();   // standard constructor


More information about the gme-commit mailing list