From c67f815120bf24e8a9c111740d5df6ff2ab7b6ba Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 12 Sep 2010 22:58:53 +0000 Subject: [PATCH] Delete wxListCtrl item data after handling its deletion event in wxMSW. We deleted the data associated with the item too soon as we did it before the handler for the item deletion event was run and this handler could still access this data. Only free the data after the handler returns now. Closes #12449. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65536 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/listctrl.cpp | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/msw/listctrl.cpp b/src/msw/listctrl.cpp index 9308756df2..71fb0231df 100644 --- a/src/msw/listctrl.cpp +++ b/src/msw/listctrl.cpp @@ -2238,22 +2238,6 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) eventType = wxEVT_COMMAND_LIST_DELETE_ITEM; event.m_itemIndex = iItem; - // delete the associated internal data - if ( wxMSWListItemData *data = MSWGetItemData(iItem) ) - { - const unsigned count = m_internalData.size(); - for ( unsigned n = 0; n < count; n++ ) - { - if ( m_internalData[n] == data ) - { - m_internalData.erase(m_internalData.begin() + n); - wxDELETE(data); - break; - } - } - - wxASSERT_MSG( !data, "invalid internal data pointer?" ); - } break; case LVN_INSERTITEM: @@ -2609,6 +2593,27 @@ bool wxListCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) m_count = 0; return true; + case LVN_DELETEITEM: + // Delete the associated internal data. Notice that this can be + // done only after the event has been handled as the data could be + // accessed during the handling of the event. + if ( wxMSWListItemData *data = MSWGetItemData(event.m_itemIndex) ) + { + const unsigned count = m_internalData.size(); + for ( unsigned n = 0; n < count; n++ ) + { + if ( m_internalData[n] == data ) + { + m_internalData.erase(m_internalData.begin() + n); + wxDELETE(data); + break; + } + } + + wxASSERT_MSG( !data, "invalid internal data pointer?" ); + } + break; + case LVN_ENDLABELEDITA: case LVN_ENDLABELEDITW: // logic here is inverted compared to all the other messages -- 2.45.2