Fixed memory leaks when wxUSE_STL=1.
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@22259 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -151,7 +151,11 @@ public:
|
|||||||
wxHashTableEqual( keyType ) ),
|
wxHashTableEqual( keyType ) ),
|
||||||
m_keyType( keyType ) { }
|
m_keyType( keyType ) { }
|
||||||
|
|
||||||
~wxHashTableBase()
|
~wxHashTableBase() { Clear(); }
|
||||||
|
|
||||||
|
size_t GetCount() const { return m_map.size(); }
|
||||||
|
|
||||||
|
void Clear()
|
||||||
{
|
{
|
||||||
if( m_keyType == wxKEY_STRING )
|
if( m_keyType == wxKEY_STRING )
|
||||||
{
|
{
|
||||||
@@ -164,26 +168,39 @@ public:
|
|||||||
delete[] tmp; // used in operator++
|
delete[] tmp; // used in operator++
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
m_map.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
size_t GetCount() const { return m_map.size(); }
|
|
||||||
protected:
|
protected:
|
||||||
void DoPut( long key, void* data )
|
void DoPut( long key, void* data )
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_INTEGER );
|
||||||
|
|
||||||
wxHashKeyValue k; k.integer = key;
|
wxHashKeyValue k; k.integer = key;
|
||||||
m_map[k] = data;
|
m_map[k] = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void DoPut( const wxChar* key, void* data )
|
void DoPut( const wxChar* key, void* data )
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_STRING );
|
||||||
|
|
||||||
wxHashKeyValue k;
|
wxHashKeyValue k;
|
||||||
k.string = new wxChar[wxStrlen(key) + 1];
|
k.string = (wxChar*)key;
|
||||||
wxStrcpy(k.string, key);
|
wxHashTableBaseBase::iterator it = m_map.find(k);
|
||||||
m_map[k] = data;
|
|
||||||
|
if( it == m_map.end() )
|
||||||
|
{
|
||||||
|
k.string = new wxChar[wxStrlen(key) + 1];
|
||||||
|
wxStrcpy(k.string, key);
|
||||||
|
m_map[k] = data;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
it->second = data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void* DoGet( long key ) const
|
void* DoGet( long key ) const
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_INTEGER );
|
||||||
|
|
||||||
wxHashKeyValue k; k.integer = key;
|
wxHashKeyValue k; k.integer = key;
|
||||||
wxHashTableBaseBase::const_iterator it = m_map.find( k );
|
wxHashTableBaseBase::const_iterator it = m_map.find( k );
|
||||||
|
|
||||||
@@ -192,6 +209,8 @@ protected:
|
|||||||
|
|
||||||
void* DoGet( const wxChar* key ) const
|
void* DoGet( const wxChar* key ) const
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_STRING );
|
||||||
|
|
||||||
wxHashKeyValue k; k.string = (wxChar*)key;
|
wxHashKeyValue k; k.string = (wxChar*)key;
|
||||||
wxHashTableBaseBase::const_iterator it = m_map.find( k );
|
wxHashTableBaseBase::const_iterator it = m_map.find( k );
|
||||||
|
|
||||||
@@ -200,6 +219,8 @@ protected:
|
|||||||
|
|
||||||
void* DoDelete( long key )
|
void* DoDelete( long key )
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_INTEGER );
|
||||||
|
|
||||||
wxHashKeyValue k; k.integer = key;
|
wxHashKeyValue k; k.integer = key;
|
||||||
wxHashTableBaseBase::iterator it = m_map.find( k );
|
wxHashTableBaseBase::iterator it = m_map.find( k );
|
||||||
|
|
||||||
@@ -216,6 +237,8 @@ protected:
|
|||||||
|
|
||||||
void* DoDelete( const wxChar* key )
|
void* DoDelete( const wxChar* key )
|
||||||
{
|
{
|
||||||
|
wxASSERT( m_keyType == wxKEY_STRING );
|
||||||
|
|
||||||
wxHashKeyValue k; k.string = (wxChar*)key;
|
wxHashKeyValue k; k.string = (wxChar*)key;
|
||||||
wxHashTableBaseBase::iterator it = m_map.find( k );
|
wxHashTableBaseBase::iterator it = m_map.find( k );
|
||||||
|
|
||||||
@@ -410,7 +433,7 @@ public:
|
|||||||
return it;
|
return it;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Clear() { m_map.clear(); }
|
void Clear() { wxHashTableBase::Clear(); }
|
||||||
private:
|
private:
|
||||||
compatibility_iterator m_iter;
|
compatibility_iterator m_iter;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user