Fixed a use-after-free problem in object list

this was uncovered by ASAN when attempting to Delete All objects with multiple instances
This commit is contained in:
Lukas Matena 2019-07-15 17:09:06 +02:00
parent 72ba890091
commit dc80616bf6

View file

@ -806,8 +806,12 @@ wxDataViewItem ObjectDataViewModel::Delete(const wxDataViewItem &item)
if (node_parent) {
if (node->m_type & (itInstanceRoot|itLayerRoot))
{
for (int i = node->GetChildCount() - 1; i >= (node->m_type & itInstanceRoot ? 1 : 0); i--)
// node can be deleted by the Delete, let's check its type while we safely can
bool is_instance_root = (node->m_type & itInstanceRoot);
for (int i = node->GetChildCount() - 1; i >= (is_instance_root ? 1 : 0); i--)
Delete(wxDataViewItem(node->GetNthChild(i)));
return parent;
}