Page MenuHomePhabricator

dataStorage->Remove( mitk::DataStorage::SetOfObjects* ) is not working
Closed, ResolvedPublic

Description

mitk::DataStorage::GetDerivations( ) returns an iternal pointer to the SetOfObjects. When Remove( ) is called with this set of objects, the loop over the list is not corretly done because the elements are removed while the loop is iterating.

Example code:
mitk::DataStorage::Pointer dataStorage;
mitk::DataTreeNode::Pointer rootNode;
(... Create a root node and 4 child nodes ...)
dataStorage->Remove( dataStorage->GetDerivations( rootNode ) );

Patch:
Modified mitk::DataStorage::FilterSetOfObjects() to always create a new list instead of returing the internal list.

Event Timeline

xplanes added a subscriber: xplanes.

Unified patch

[SVN revision 21986]
FIX (#3426): fixed crash while removing a children node subset from the DataStorage, adapted unit test.

[SVN revision 21990]
COMP (#3426): modified if cases to prevent segmentation fault using linux

[SVN revision 21992]
COMP (#3426): due to strange behavior on gcc 4.3 systems test order was changed

mitk::DataStorageTest failed with "segmentation fault" using gcc 4.3 compiler but the test passes while using valgrind.

Segmentation fault occurs in the test case "Checking reference count of node after add and remove" during watcher->GetReferenceCount(), in ReferenceCountWatcher::GetReferenceCount() return m_Object->GetReferenceCount()

The error seems to occur only on linux systems using gcc 4.3, dart clients using gcc 4.4 or MinGW (with gcc 4.4) passed the test.