Bookmarks: assure proper recursive cleanup of ItemData for all levels of a tree item

This commit is contained in:
vsonnier 2017-03-03 22:49:58 +01:00
parent aab899d63c
commit b30f9e9bbb
2 changed files with 18 additions and 6 deletions

View File

@ -1597,8 +1597,10 @@ BookmarkRangeEntryPtr BookmarkView::makeActiveRangeEntry() {
void BookmarkView::DeleteSingleItem(wxTreeItemId item) { void BookmarkView::DeleteSingleItem(wxTreeItemId item) {
//free the associated TreeItemData*, because contrary to doc, the associated data is not freed automatically by m_treeView->Delete(item) ! //free the associated TreeItemData*, because contrary to doc,
// this is needed to dec the ref count of shared_ptr within TreeViewItem. // the associated data is not freed automatically by m_treeView->Delete(item) !
// this is also needed to decrement the ref count of shared_ptr within TreeViewItem,
//and prevent further memory leaks.
// (see source of vxWidgets 3.1) // (see source of vxWidgets 3.1)
TreeViewItem *itemData = itemToTVI(item); TreeViewItem *itemData = itemToTVI(item);
if (itemData != NULL) { if (itemData != NULL) {
@ -1613,6 +1615,14 @@ void BookmarkView::DeleteSingleItem(wxTreeItemId item) {
void BookmarkView::DeleteChildrenOfItem(wxTreeItemId item) { void BookmarkView::DeleteChildrenOfItem(wxTreeItemId item) {
FreeItemDataOfItemRecursively(item);
//this delete is naturally recursive.
m_treeView->DeleteChildren(item);
}
void BookmarkView::FreeItemDataOfItemRecursively(wxTreeItemId item) {
wxTreeItemIdValue cookieSearch; wxTreeItemIdValue cookieSearch;
wxTreeItemId currentChild = m_treeView->GetFirstChild(item, cookieSearch); wxTreeItemId currentChild = m_treeView->GetFirstChild(item, cookieSearch);
@ -1625,10 +1635,11 @@ void BookmarkView::DeleteChildrenOfItem(wxTreeItemId item) {
m_treeView->SetItemData(currentChild, NULL); m_treeView->SetItemData(currentChild, NULL);
} }
currentChild = m_treeView->GetNextChild(item, cookieSearch); //Search children and Free item data recursively.
} FreeItemDataOfItemRecursively(currentChild);
m_treeView->DeleteChildren(item); currentChild = m_treeView->GetNextChild(item, cookieSearch);
} //end while
} }

View File

@ -152,6 +152,7 @@ protected:
void SetTreeItemData(const wxTreeItemId& item, wxTreeItemData *data); void SetTreeItemData(const wxTreeItemId& item, wxTreeItemData *data);
void DeleteSingleItem(wxTreeItemId item); void DeleteSingleItem(wxTreeItemId item);
void DeleteChildrenOfItem(wxTreeItemId item); void DeleteChildrenOfItem(wxTreeItemId item);
void FreeItemDataOfItemRecursively(wxTreeItemId item);
MouseTracker mouseTracker; MouseTracker mouseTracker;