forked from qt-creator/qt-creator
AutoTest: Fix potential crash
It is a bad idea to remove child items while iterating over them.
Introduced a while ago, but forgotten to fix in f00a113e.
Change-Id: I8d335cec34c2e6a9e7dff99d10c68066ffa8933d
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -67,14 +67,7 @@ TestTreeModel *TestTreeModel::instance()
|
|||||||
|
|
||||||
TestTreeModel::~TestTreeModel()
|
TestTreeModel::~TestTreeModel()
|
||||||
{
|
{
|
||||||
const Utils::TreeItem *invisibleRoot = rootItem();
|
removeTestRootNodes();
|
||||||
const int frameworkRootCount = invisibleRoot ? invisibleRoot->childCount() : 0;
|
|
||||||
for (int row = frameworkRootCount - 1; row >= 0; --row) {
|
|
||||||
Utils::TreeItem *item = invisibleRoot->childAt(row);
|
|
||||||
item->removeChildren();
|
|
||||||
takeItem(item); // do NOT delete the item as it's still a ptr hold by TestFrameworkManager
|
|
||||||
}
|
|
||||||
|
|
||||||
s_instance = nullptr;
|
s_instance = nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,10 +163,7 @@ QList<TestConfiguration *> TestTreeModel::getSelectedTests() const
|
|||||||
void TestTreeModel::syncTestFrameworks()
|
void TestTreeModel::syncTestFrameworks()
|
||||||
{
|
{
|
||||||
// remove all currently registered
|
// remove all currently registered
|
||||||
for (Utils::TreeItem *item : *rootItem()) {
|
removeTestRootNodes();
|
||||||
item->removeChildren();
|
|
||||||
takeItem(item); // do NOT delete the item as it's still a ptr hold by TestFrameworkManager
|
|
||||||
}
|
|
||||||
|
|
||||||
TestFrameworkManager *frameworkManager = TestFrameworkManager::instance();
|
TestFrameworkManager *frameworkManager = TestFrameworkManager::instance();
|
||||||
QVector<Core::Id> sortedIds = frameworkManager->sortedActiveFrameworkIds();
|
QVector<Core::Id> sortedIds = frameworkManager->sortedActiveFrameworkIds();
|
||||||
@@ -285,6 +275,17 @@ void TestTreeModel::removeAllTestItems()
|
|||||||
emit testTreeModelChanged();
|
emit testTreeModelChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TestTreeModel::removeTestRootNodes()
|
||||||
|
{
|
||||||
|
const Utils::TreeItem *invisibleRoot = rootItem();
|
||||||
|
const int frameworkRootCount = invisibleRoot ? invisibleRoot->childCount() : 0;
|
||||||
|
for (int row = frameworkRootCount - 1; row >= 0; --row) {
|
||||||
|
Utils::TreeItem *item = invisibleRoot->childAt(row);
|
||||||
|
item->removeChildren();
|
||||||
|
takeItem(item); // do NOT delete the item as it's still a ptr held by TestFrameworkManager
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef WITH_TESTS
|
#ifdef WITH_TESTS
|
||||||
// we're inside tests - so use some internal knowledge to make testing easier
|
// we're inside tests - so use some internal knowledge to make testing easier
|
||||||
TestTreeItem *qtRootNode()
|
TestTreeItem *qtRootNode()
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ private:
|
|||||||
void onParseResultReady(const TestParseResultPtr result);
|
void onParseResultReady(const TestParseResultPtr result);
|
||||||
void handleParseResult(const TestParseResult *result, TestTreeItem *rootNode);
|
void handleParseResult(const TestParseResult *result, TestTreeItem *rootNode);
|
||||||
void removeAllTestItems();
|
void removeAllTestItems();
|
||||||
|
void removeTestRootNodes();
|
||||||
void removeFiles(const QStringList &files);
|
void removeFiles(const QStringList &files);
|
||||||
bool sweepChildren(TestTreeItem *item);
|
bool sweepChildren(TestTreeItem *item);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user