From: Václav Slavík Date: Wed, 2 Feb 2000 21:17:40 +0000 (+0000) Subject: fixed DeleteContents inconsistency: didn't free memory if DeleteContents called befor... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/c7fb814ac347c97d7e1d342ceb227dab50c721f6?ds=sidebyside fixed DeleteContents inconsistency: didn't free memory if DeleteContents called before inserting data (and creating wxList) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@5812 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/hash.h b/include/wx/hash.h index 2e17fb019c..e5450054f0 100644 --- a/include/wx/hash.h +++ b/include/wx/hash.h @@ -104,7 +104,7 @@ class WXDLLEXPORT wxHashTable: public wxObject private: size_t m_count; // number of elements in the hashtable - + bool m_deleteContents; }; #endif diff --git a/src/common/hash.cpp b/src/common/hash.cpp index 4c6ad97c6d..5110f8228c 100644 --- a/src/common/hash.cpp +++ b/src/common/hash.cpp @@ -37,6 +37,7 @@ wxHashTable::wxHashTable (int the_key_type, int size) hash_table = (wxList**) NULL; Create(the_key_type, size); m_count = 0; + m_deleteContents = FALSE; /* n = size; current_position = -1; @@ -110,7 +111,10 @@ void wxHashTable::Put (long key, long value, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (value, object); m_count++; @@ -125,7 +129,10 @@ void wxHashTable::Put (long key, const wxChar *value, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (value, object); m_count++; @@ -140,8 +147,11 @@ void wxHashTable::Put (long key, wxObject * object) int position = (int) (k % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_INTEGER); - + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } + hash_table[position]->Append (k, object); m_count++; } @@ -151,7 +161,10 @@ void wxHashTable::Put (const wxChar *key, wxObject * object) int position = (int) (MakeKey (key) % n); if (!hash_table[position]) + { hash_table[position] = new wxList (wxKEY_STRING); + if (m_deleteContents) hash_table[position]->DeleteContents(TRUE); + } hash_table[position]->Append (key, object); m_count++; @@ -369,6 +382,7 @@ wxNode *wxHashTable::Next (void) void wxHashTable::DeleteContents (bool flag) { int i; + m_deleteContents = flag; for (i = 0; i < n; i++) { if (hash_table[i])