Page MenuHomePhabricator

Possible double-delete of DataNode
Closed, ResolvedPublic

Description

Issues with DataNode delete events and double deletions due to smart-pointer constructions popped up in this thread:

http://thread.gmane.org/gmane.comp.lib.mitk.user/5616

The main issue is that if a mitk::DataNode object is destroyed (last smart-pointer goes out of scope), the itk::Object fires a itk::DeleteEvent() which is routed through the event system in mitk::DataStorage. If a callback function calls itself methods on mitk::DataStorage using such a DataNode raw pointer, it is important that such mitk::DataStorage methods do not construct temporary smart pointers from the raw pointer since this would lead to double deletion.

One method not following this rule is

mitk::StandaloneDataStorage::GetRelations(const mitk::DataNode* node, const AdjacencyList& relation, const NodePredicateBase* condition, bool onlyDirectlyRelated) const

It implicitly constructs a temporary smart pointer e.g. by calling relation.find(node). All temporary smart pointers need to be avoided or the reference count needs to be managed manually.

Event Timeline

User goerres has pushed new remote branch:

bug-18672-DoubleDeleteGuardInDataManagerView

The actual problem, as stated in the thread, is because of inconvenient smart pointer usage in the data manager view.

By changing the element type of selected nodes from pointer to smart pointer, recursive deletion of elements in the data storage becomes possible in the QmitkAbstractView delete event.

[625b57]: Merge branch 'bug-18672-DoubleDeleteGuardInDataManagerViewCherryPick'

Merged commits:

2015-04-01 16:33:43 Joseph Görres [0880f4]
introduced smart pointer in datamanagerview to prevent recursive double deletion of data nodes