]> git.saurik.com Git - wxWidgets.git/commitdiff
fix memory leak; allocate the DC before SetFont() is called on the status bar
authorFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 9 Feb 2009 00:53:58 +0000 (00:53 +0000)
committerFrancesco Montorsi <f18m_cpp217828@yahoo.it>
Mon, 9 Feb 2009 00:53:58 +0000 (00:53 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58788 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/msw/statusbar.h
src/msw/statusbar.cpp

index 55a1f16c83ab060bce03c3ea3148451f0f9e8747..070e1db817e04815ecbc8146040b4374314432b2 100644 (file)
@@ -26,6 +26,7 @@ public:
                 long style = wxST_SIZEGRIP,
                 const wxString& name = wxStatusBarNameStr)
     {
+        m_pDC = NULL;
         (void)Create(parent, id, style, name);
     }
 
index 0dcc35899c083630817b7566c10d04a8bb2f1309..b5207576f5d3a80f993ab7b1fa587d2d1e778ae1 100644 (file)
@@ -123,6 +123,12 @@ bool wxStatusBar::Create(wxWindow *parent,
 
     SetFieldsCount(1);
     SubclassWin(m_hWnd);
+
+    // cache the DC instance used by UpdateFieldText:
+    // NOTE: create the DC before calling InheritAttributes() since
+    //       it may result in a call to our SetFont()
+    m_pDC = new wxClientDC(this);
+
     InheritAttributes();
 
     SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_MENUBAR));
@@ -135,9 +141,6 @@ bool wxStatusBar::Create(wxWindow *parent,
     // work correctly, we need to wait until we return to the main loop
     PostSizeEventToParent();
 
-    // cache the DC instance used by UpdateFieldText
-    m_pDC = new wxClientDC(this);
-
     return true;
 }
 
@@ -147,6 +150,8 @@ wxStatusBar::~wxStatusBar()
     // frame is not - otherwise statusbar leaves a hole in the place it used to
     // occupy
     PostSizeEventToParent();
+
+    wxDELETE(m_pDC);
 }
 
 bool wxStatusBar::SetFont(const wxFont& font)
@@ -154,7 +159,7 @@ bool wxStatusBar::SetFont(const wxFont& font)
     if (!wxWindow::SetFont(font))
         return false;
 
-    m_pDC->SetFont(font);
+    if (m_pDC) m_pDC->SetFont(font);
     return true;
 }