From 66806a0bf07e9973a4b3e5ff58f98b9e439bab08 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 2 Feb 2000 21:17:25 +0000 Subject: [PATCH] fixing memory leaks & mem tracing false alerts git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5811 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/html/htmlwin.h | 15 ++++++++++----- include/wx/mimetype.h | 4 ++++ src/common/mimecmn.cpp | 24 ++++++++++++++++++++++++ src/html/htmlwin.cpp | 15 +++++++++++---- 4 files changed, 49 insertions(+), 9 deletions(-) diff --git a/include/wx/html/htmlwin.h b/include/wx/html/htmlwin.h index 73de0e2a99..0fd05a4d01 100644 --- a/include/wx/html/htmlwin.h +++ b/include/wx/html/htmlwin.h @@ -59,11 +59,13 @@ class WXDLLEXPORT HtmlHistoryItem : public wxObject WX_DECLARE_EXPORTED_OBJARRAY(HtmlHistoryItem, HtmlHistoryArray); - +class wxHtmlWinModule; class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow { DECLARE_DYNAMIC_CLASS(wxHtmlWindow) + + friend class wxHtmlWinModule; public: wxHtmlWindow() : wxScrolledWindow() {}; @@ -141,9 +143,6 @@ class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow // called when users clicked on hypertext link. Default behavior is to // call LoadPage(loc) - static void CleanUpStatics(); - // cleans static variables - wxHtmlWinParser *GetParser() const { return m_Parser; } // return a pointer to the parser. @@ -166,6 +165,9 @@ class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow virtual wxHtmlFilter *GetDefaultFilter() {return new wxHtmlFilterPlainText;} // returns new filter (will be stored into m_DefaultFilter variable) + static void CleanUpStatics(); + // cleans static variables + protected: wxHtmlContainerCell *m_Cell; @@ -204,13 +206,16 @@ class WXDLLEXPORT wxHtmlWindow : public wxScrolledWindow // contains last link name int m_tmpCanDrawLocks; // if >0 contents of the window is not redrawn - // (in order to avoid ugly bliking) + // (in order to avoid ugly blinking) static wxList m_Filters; // list of HTML filters static wxHtmlFilter *m_DefaultFilter; // this filter is used when no filter is able to read some file + static wxCursor *s_cur_hand; + static wxCursor *s_cur_arrow; + HtmlHistoryArray m_History; int m_HistoryPos; // browser history diff --git a/include/wx/mimetype.h b/include/wx/mimetype.h index 58a6bf7e2d..dcd26cafa4 100644 --- a/include/wx/mimetype.h +++ b/include/wx/mimetype.h @@ -30,6 +30,8 @@ class wxMimeTypesManagerImpl; #include "wx/string.h" #include "wx/dynarray.h" +class wxMimeTypeCmnModule; + // This class holds information about a given "file type". File type is the // same as MIME type under Unix, but under Windows it corresponds more to an // extension than to MIME type (in fact, several extensions may correspond to a @@ -228,6 +230,8 @@ private: // if m_impl is NULL, create one void EnsureImpl(); + + friend class wxMimeTypeCmnModule; }; diff --git a/src/common/mimecmn.cpp b/src/common/mimecmn.cpp index dc28cce7a5..25a0eedb28 100644 --- a/src/common/mimecmn.cpp +++ b/src/common/mimecmn.cpp @@ -15,6 +15,7 @@ // for compilers that support precompilation, includes "wx.h". #include "wx/wxprec.h" +#include "wx/module.h" #ifdef __BORLANDC__ #pragma hdrstop @@ -341,6 +342,29 @@ static wxMimeTypesManager gs_mimeTypesManager; wxMimeTypesManager * wxTheMimeTypesManager = &gs_mimeTypesManager; + + + +class wxMimeTypeCmnModule: public wxModule +{ +DECLARE_DYNAMIC_CLASS(wxMimeTypeCmnModule) +public: + wxMimeTypeCmnModule() : wxModule() {} + bool OnInit() { return TRUE; } + void OnExit() + { // this avoids false memory leak allerts: + if (gs_mimeTypesManager.m_impl != NULL) + { + delete gs_mimeTypesManager.m_impl; + gs_mimeTypesManager.m_impl = NULL; + } + } +}; + +IMPLEMENT_DYNAMIC_CLASS(wxMimeTypeCmnModule, wxModule) + + + #endif // wxUSE_FILE && wxUSE_TEXTFILE diff --git a/src/html/htmlwin.cpp b/src/html/htmlwin.cpp index 6a8bfcfa58..e8f244474f 100644 --- a/src/html/htmlwin.cpp +++ b/src/html/htmlwin.cpp @@ -419,6 +419,8 @@ void wxHtmlWindow::HistoryClear() wxList wxHtmlWindow::m_Filters; wxHtmlFilter *wxHtmlWindow::m_DefaultFilter = NULL; +wxCursor *wxHtmlWindow::s_cur_hand = NULL; +wxCursor *wxHtmlWindow::s_cur_arrow = NULL; void wxHtmlWindow::CleanUpStatics() { @@ -426,7 +428,8 @@ void wxHtmlWindow::CleanUpStatics() m_DefaultFilter = NULL; m_Filters.DeleteContents(TRUE); m_Filters.Clear(); - + if (s_cur_hand) delete s_cur_hand; + if (s_cur_arrow) delete s_cur_arrow; } @@ -504,7 +507,11 @@ void wxHtmlWindow::OnMouseEvent(wxMouseEvent& event) void wxHtmlWindow::OnIdle(wxIdleEvent& event) { - static wxCursor cur_hand(wxCURSOR_HAND), cur_arrow(wxCURSOR_ARROW); + if (s_cur_hand == NULL) + { + s_cur_hand = new wxCursor(wxCURSOR_HAND); + s_cur_arrow = new wxCursor(wxCURSOR_ARROW); + } if (m_tmpMouseMoved && (m_Cell != NULL)) { int sx, sy; @@ -518,11 +525,11 @@ void wxHtmlWindow::OnIdle(wxIdleEvent& event) if (lnk != m_tmpLastLink) { if (lnk == NULL) { - SetCursor(cur_arrow); + SetCursor(*s_cur_arrow); if (m_RelatedStatusBar != -1) m_RelatedFrame -> SetStatusText(wxEmptyString, m_RelatedStatusBar); } else { - SetCursor(cur_hand); + SetCursor(*s_cur_hand); if (m_RelatedStatusBar != -1) m_RelatedFrame -> SetStatusText(lnk -> GetHref(), m_RelatedStatusBar); } -- 2.45.2