From c7fb814ac347c97d7e1d342ceb227dab50c721f6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 2 Feb 2000 21:17:40 +0000 Subject: [PATCH] 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 --- include/wx/hash.h | 2 +- src/common/hash.cpp | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) 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]) -- 2.45.2