From: Robert Roebling Date: Wed, 6 Sep 2006 13:49:42 +0000 (+0000) Subject: Applied 1215477, fixing a crash by properly removing X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/5949d30725e8af5b7938c86102b3e37da7caedd2 Applied 1215477, fixing a crash by properly removing a file system handler in a module. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/filesys.h b/include/wx/filesys.h index 354d940275..f24323363c 100644 --- a/include/wx/filesys.h +++ b/include/wx/filesys.h @@ -188,6 +188,10 @@ public: // In fact, this class is only front-end to the FS handlers :-) static void AddHandler(wxFileSystemHandler *handler); + // Removes FS handler + static wxFileSystemHandler* RemoveHandler(wxFileSystemHandler *handler); + + // Returns true if there is a handler which can open the given location. static bool HasHandlerForPath(const wxString& location); diff --git a/src/common/filesys.cpp b/src/common/filesys.cpp index 425be7057c..2d44cf8c5f 100644 --- a/src/common/filesys.cpp +++ b/src/common/filesys.cpp @@ -487,6 +487,20 @@ void wxFileSystem::AddHandler(wxFileSystemHandler *handler) m_Handlers.Insert((size_t)0, handler); } +wxFileSystemHandler* wxFileSystem::RemoveHandler(wxFileSystemHandler *handler) +{ + // if handler has already been removed (or deleted) + // we return NULL. This is by design in case + // CleanUpHandlers() is called before RemoveHandler + // is called, as we cannot control the order + // which modules are unloaded + if (!m_Handlers.DeleteObject(handler)) + return NULL; + + return handler; +} + + bool wxFileSystem::HasHandlerForPath(const wxString &location) { for ( wxList::compatibility_iterator node = m_Handlers.GetFirst(); @@ -589,15 +603,28 @@ class wxFileSystemModule : public wxModule DECLARE_DYNAMIC_CLASS(wxFileSystemModule) public: + wxFileSystemModule() : + wxModule(), + m_handler(NULL) + { + } + virtual bool OnInit() { - wxFileSystem::AddHandler(new wxLocalFSHandler); + m_handler = new wxLocalFSHandler; + wxFileSystem::AddHandler(m_handler); return true; } virtual void OnExit() { + delete wxFileSystem::RemoveHandler(m_handler); + wxFileSystem::CleanUpHandlers(); } + + private: + wxFileSystemHandler* m_handler; + }; IMPLEMENT_DYNAMIC_CLASS(wxFileSystemModule, wxModule) diff --git a/src/common/fs_inet.cpp b/src/common/fs_inet.cpp index 9f3551a742..26080da987 100644 --- a/src/common/fs_inet.cpp +++ b/src/common/fs_inet.cpp @@ -140,12 +140,26 @@ class wxFileSystemInternetModule : public wxModule DECLARE_DYNAMIC_CLASS(wxFileSystemInternetModule) public: + wxFileSystemInternetModule() : + wxModule(), + m_handler(NULL) + { + } + virtual bool OnInit() { - wxFileSystem::AddHandler(new wxInternetFSHandler); + m_handler = new wxInternetFSHandler; + wxFileSystem::AddHandler(m_handler); return true; } - virtual void OnExit() {} + + virtual void OnExit() + { + delete wxFileSystem::RemoveHandler(m_handler); + } + + private: + wxFileSystemHandler* m_handler; }; IMPLEMENT_DYNAMIC_CLASS(wxFileSystemInternetModule, wxModule)