Some defensive code which may prevent a freed-memory-access.

Fixes https://gitlab.com/kicad/code/kicad/issues/5747
This commit is contained in:
Jeff Young 2020-09-23 18:42:35 +01:00
parent e0ee420cb6
commit ac4978cf8a
1 changed files with 20 additions and 3 deletions

View File

@ -432,18 +432,32 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
return;
}
int lastGood = -1;
bool found = false;
if( m_view )
m_view->UnselectAll();
for( int i = m_rcItemsProvider->GetCount() - 1; i >= 0; --i )
{
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
MARKER_BASE* marker = rcItem->GetParent();
bool excluded = marker ? marker->IsExcluded() : false;
std::shared_ptr<RC_ITEM> rcItem = m_rcItemsProvider->GetItem( i );
MARKER_BASE* marker = rcItem->GetParent();
bool excluded = marker ? marker->IsExcluded() : false;
if( aCurrentOnly && rcItem != current_item )
{
if( found && lastGood >= 0 )
break;
lastGood = i;
continue;
}
if( excluded && !aIncludeExclusions )
continue;
found = true;
wxDataViewItem markerItem = ToItem( m_tree[i] );
wxDataViewItemArray childItems;
wxDataViewItem parentItem = ToItem( m_tree[i]->m_Parent );
@ -466,6 +480,9 @@ void RC_TREE_MODEL::DeleteItems( bool aCurrentOnly, bool aIncludeExclusions, boo
m_rcItemsProvider->DeleteItem( i, aDeep && aCurrentOnly );
}
if( m_view && aCurrentOnly && lastGood >= 0 )
m_view->Select( ToItem( m_tree[ lastGood ] ) );
if( !aCurrentOnly )
{
m_rcItemsProvider->DeleteAllItems( aIncludeExclusions, aDeep );