]> git.saurik.com Git - wxWidgets.git/commitdiff
Safeguard against redundant registration of the same wxAnyValueType instance (by...
authorJaakko Salli <jaakko.salli@dnainternet.net>
Tue, 27 Apr 2010 13:26:45 +0000 (13:26 +0000)
committerJaakko Salli <jaakko.salli@dnainternet.net>
Tue, 27 Apr 2010 13:26:45 +0000 (13:26 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@64159 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/common/any.cpp

index ac960455b32e90cc22f3d8b1a4dfd2f14551d360..79aed46067160defff177be8fb808a11682606d6 100644 (file)
@@ -28,6 +28,7 @@
 #include "wx/vector.h"
 #include "wx/module.h"
 #include "wx/hashmap.h"
+#include "wx/hashset.h"
 
 using namespace wxPrivate;
 
@@ -45,6 +46,11 @@ WX_DECLARE_HASH_MAP(wxAnyValueType*,
 
 #endif
 
+WX_DECLARE_HASH_SET(wxAnyValueType*,
+                    wxPointerHash,
+                    wxPointerEqual,
+                    wxAnyValueTypePtrSet);
+
 //
 // Helper class to manage wxAnyValueType instances and and other
 // related global variables (such as wxAny<->wxVariant type association).
@@ -65,13 +71,20 @@ public:
     #if wxUSE_VARIANT
         m_anyToVariant.clear();
     #endif
-        for ( size_t i=0; i<m_valueTypes.size(); i++ )
-            delete m_valueTypes[i];
+
+        wxAnyValueTypePtrSet::iterator it;
+        for ( it = m_valueTypes.begin(); it != m_valueTypes.end(); ++it )
+        {
+            delete *it;
+        }
     }
 
     void RegisterValueType(wxAnyValueType* valueType)
     {
-        m_valueTypes.push_back(valueType);
+        // Let's store value types in set to prevent deleting the same object
+        // several times (it may be possible, under certain conditions, that
+        // the same wxAnyValueType instance gets registered twice)
+        m_valueTypes.insert(valueType);
     }
 
 #if wxUSE_VARIANT
@@ -134,7 +147,7 @@ public:
 #endif
 
 private:
-    wxVector<wxAnyValueType*>               m_valueTypes;
+    wxAnyValueTypePtrSet                    m_valueTypes;
 #if wxUSE_VARIANT
     wxAnyTypeToVariantDataFactoryMap        m_anyToVariant;
     wxVector<wxAnyToVariantRegistration*>   m_anyToVariantRegs;