forked from qt-creator/qt-creator
Aggregation: Fix crash when components are in parent-child relationship
and the child is deleted first. Change-Id: Idea3b4a3410bda99a8727551e2cbeab3a7b95d85 Reviewed-by: Christian Stenger <christian.stenger@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -193,6 +193,9 @@ void Aggregate::deleteSelf(QObject *obj)
|
||||
QWriteLocker locker(&lock());
|
||||
aggregateMap().remove(obj);
|
||||
m_components.removeAll(obj);
|
||||
// Avoid issues if obj was child of another component of the aggregate.
|
||||
// The parent is deleted in ~Aggregate and might still have a reference on obj
|
||||
obj->setParent({});
|
||||
}
|
||||
delete this;
|
||||
}
|
||||
|
||||
@@ -78,6 +78,24 @@ void tst_Aggregate::deleteAggregation()
|
||||
component1 = new Interface1;
|
||||
delete component1;
|
||||
QVERIFY(component1 == 0);
|
||||
|
||||
// do not crash if components are in a child/parent relationship
|
||||
// parent deleted first
|
||||
aggregation = new Aggregation::Aggregate;
|
||||
component1 = new Interface1;
|
||||
component2 = new Interface2;
|
||||
component2->setParent(component1);
|
||||
aggregation->add(component1);
|
||||
aggregation->add(component2);
|
||||
delete component1;
|
||||
// child deleted first
|
||||
aggregation = new Aggregation::Aggregate;
|
||||
component1 = new Interface1;
|
||||
component2 = new Interface2;
|
||||
component2->setParent(component1);
|
||||
aggregation->add(component1);
|
||||
aggregation->add(component2);
|
||||
delete component2;
|
||||
}
|
||||
|
||||
void tst_Aggregate::queryAggregation()
|
||||
|
||||
Reference in New Issue
Block a user