]> git.saurik.com Git - wxWidgets.git/commitdiff
Applied 1215477, fixing a crash by properly removing
authorRobert Roebling <robert@roebling.de>
Wed, 6 Sep 2006 13:49:42 +0000 (13:49 +0000)
committerRobert Roebling <robert@roebling.de>
Wed, 6 Sep 2006 13:49:42 +0000 (13:49 +0000)
    a file system handler in a module.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@41033 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/filesys.h
src/common/filesys.cpp
src/common/fs_inet.cpp

index 354d940275d8bfdc8ba94c6e1ccba26737610e9a..f24323363ce04afbc39a848234c00b0e8eac6ff8 100644 (file)
@@ -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);
 
index 425be7057ce7a6ea5a726925442f2c4ba105d649..2d44cf8c5fc5028037469240f4346b75b17d377a 100644 (file)
@@ -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)
index 9f3551a742afdcc9202e408e760a6b50dfa1ab87..26080da98779d71a5534e0583a5ba6b509ebba4d 100644 (file)
@@ -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)