From f9334fda39e7b8bc4eacd4eae1ddc6140cad4785 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Oct 2015 01:00:59 +0200 Subject: [PATCH] Fix crash when deleting items in wxTreeListCtrl An invalid pointer was dereferenced after being deleted as ToDVI(item) checked the item parent, i.e. used it, even though the item was already invalid. Closes #17198. --- src/generic/treelist.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/generic/treelist.cpp b/src/generic/treelist.cpp index 74992994c1..e93a708790 100644 --- a/src/generic/treelist.cpp +++ b/src/generic/treelist.cpp @@ -733,7 +733,10 @@ void wxTreeListModel::DeleteItem(Node* item) previous->DeleteNext(); } - ItemDeleted(ToDVI(parent), ToDVI(item)); + // Note that the item is already deleted by now, so we can't use it in any + // way, e.g. by calling ToDVI(item) which does dereference the pointer, but + // ToNonRootDVI() that we use here does not. + ItemDeleted(ToDVI(parent), ToNonRootDVI(item)); } void wxTreeListModel::DeleteAllItems()