From: Mattia Barbon Date: Sun, 23 Nov 2003 08:17:57 +0000 (+0000) Subject: Avoid double free in wxComboBox::SetClientObject. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/f148f2bac3fb0fa6d984050fb940112da150aeff?hp=8e5ec9cc58bc1508aadf5bc2387609b245358a74 Avoid double free in wxComboBox::SetClientObject. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@24640 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/mac/choice.h b/include/wx/mac/choice.h index ea9756f1a4..26ac3359c0 100644 --- a/include/wx/mac/choice.h +++ b/include/wx/mac/choice.h @@ -72,11 +72,14 @@ public: protected: virtual wxSize DoGetBestSize() const ; + +public: // for wxComboBox only virtual void DoSetItemClientData( int n, void* clientData ); virtual void* DoGetItemClientData( int n ) const; virtual void DoSetItemClientObject( int n, wxClientData* clientData ); virtual wxClientData* DoGetItemClientObject( int n ) const; +protected: // free all memory we have (used by Clear() and dtor) // prevent collision with some BSD definitions of macro Free() void FreeData(); diff --git a/include/wx/mac/combobox.h b/include/wx/mac/combobox.h index e07db8a962..d2528db237 100644 --- a/include/wx/mac/combobox.h +++ b/include/wx/mac/combobox.h @@ -106,6 +106,8 @@ protected: virtual void DoSetItemClientObject(int n, wxClientData* clientData) ; virtual wxClientData* DoGetItemClientObject(int n) const ; + void FreeData(); + // the subcontrols wxTextCtrl* m_text; wxChoice* m_choice; diff --git a/src/mac/carbon/combobox.cpp b/src/mac/carbon/combobox.cpp index 830e8564a7..c3c5660bbf 100644 --- a/src/mac/carbon/combobox.cpp +++ b/src/mac/carbon/combobox.cpp @@ -414,31 +414,47 @@ int wxComboBox::DoInsert(const wxString& item, int pos) void wxComboBox::DoSetItemClientData(int n, void* clientData) { - return m_choice->SetClientData( n , clientData ) ; + return m_choice->DoSetItemClientData( n , clientData ) ; } void* wxComboBox::DoGetItemClientData(int n) const { - return m_choice->GetClientData( n ) ; + return m_choice->DoGetItemClientData( n ) ; } void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) { - return m_choice->SetClientObject( n , clientData ) ; + return m_choice->DoSetItemClientObject( n , clientData ) ; } wxClientData* wxComboBox::DoGetItemClientObject(int n) const { - return m_choice->GetClientObject( n ) ; + return m_choice->DoGetItemClientObject( n ) ; +} + +void wxComboBox::FreeData() +{ + if ( HasClientObjectData() ) + { + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + SetClientObject( n, NULL ); + } + } } void wxComboBox::Delete(int n) { + // force client object deletion + if( HasClientObjectData() ) + SetClientObject( n, NULL ); m_choice->Delete( n ); } void wxComboBox::Clear() { + FreeData(); m_choice->Clear(); } diff --git a/src/mac/combobox.cpp b/src/mac/combobox.cpp index 830e8564a7..c3c5660bbf 100644 --- a/src/mac/combobox.cpp +++ b/src/mac/combobox.cpp @@ -414,31 +414,47 @@ int wxComboBox::DoInsert(const wxString& item, int pos) void wxComboBox::DoSetItemClientData(int n, void* clientData) { - return m_choice->SetClientData( n , clientData ) ; + return m_choice->DoSetItemClientData( n , clientData ) ; } void* wxComboBox::DoGetItemClientData(int n) const { - return m_choice->GetClientData( n ) ; + return m_choice->DoGetItemClientData( n ) ; } void wxComboBox::DoSetItemClientObject(int n, wxClientData* clientData) { - return m_choice->SetClientObject( n , clientData ) ; + return m_choice->DoSetItemClientObject( n , clientData ) ; } wxClientData* wxComboBox::DoGetItemClientObject(int n) const { - return m_choice->GetClientObject( n ) ; + return m_choice->DoGetItemClientObject( n ) ; +} + +void wxComboBox::FreeData() +{ + if ( HasClientObjectData() ) + { + size_t count = GetCount(); + for ( size_t n = 0; n < count; n++ ) + { + SetClientObject( n, NULL ); + } + } } void wxComboBox::Delete(int n) { + // force client object deletion + if( HasClientObjectData() ) + SetClientObject( n, NULL ); m_choice->Delete( n ); } void wxComboBox::Clear() { + FreeData(); m_choice->Clear(); }