tst_QSortFilterProxyModel: fix mem-leaks
tst_QSortFilterProxyModel::doubleProxySelectionSetSourceModel() leaked _everything_, driving asan nuts. Allocate objects on the stack instead; now it's asan-clean. Pick-to: 6.6 6.5 6.2 5.15 Change-Id: I721e797e02b1daec9e2b5e3d4ef612a42b2e3492 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
parent
53b6c88a25
commit
9f8449a054
@ -3235,36 +3235,36 @@ void tst_QSortFilterProxyModel::removeRowsRecursive()
|
||||
|
||||
void tst_QSortFilterProxyModel::doubleProxySelectionSetSourceModel()
|
||||
{
|
||||
QStandardItemModel *model1 = new QStandardItemModel;
|
||||
QStandardItem *parentItem = model1->invisibleRootItem();
|
||||
QStandardItemModel model1;
|
||||
QStandardItem *parentItem = model1.invisibleRootItem();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
QStandardItem *item = new QStandardItem(QLatin1String("model1 item ") + QString::number(i));
|
||||
parentItem->appendRow(item);
|
||||
parentItem = item;
|
||||
}
|
||||
|
||||
QStandardItemModel *model2 = new QStandardItemModel;
|
||||
QStandardItem *parentItem2 = model2->invisibleRootItem();
|
||||
QStandardItemModel model2;
|
||||
QStandardItem *parentItem2 = model2.invisibleRootItem();
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
QStandardItem *item = new QStandardItem(QLatin1String("model2 item ") + QString::number(i));
|
||||
parentItem2->appendRow(item);
|
||||
parentItem2 = item;
|
||||
}
|
||||
|
||||
QSortFilterProxyModel *toggleProxy = new QSortFilterProxyModel;
|
||||
toggleProxy->setSourceModel(model1);
|
||||
QSortFilterProxyModel toggleProxy;
|
||||
toggleProxy.setSourceModel(&model1);
|
||||
|
||||
QSortFilterProxyModel *proxyModel = new QSortFilterProxyModel;
|
||||
proxyModel->setSourceModel(toggleProxy);
|
||||
QSortFilterProxyModel proxyModel;
|
||||
proxyModel.setSourceModel(&toggleProxy);
|
||||
|
||||
QModelIndex mi = proxyModel->index(0, 0, proxyModel->index(0, 0, proxyModel->index(0, 0)));
|
||||
QItemSelectionModel ism(proxyModel);
|
||||
QModelIndex mi = proxyModel.index(0, 0, proxyModel.index(0, 0, proxyModel.index(0, 0)));
|
||||
QItemSelectionModel ism(&proxyModel);
|
||||
ism.select(mi, QItemSelectionModel::Select);
|
||||
QModelIndexList mil = ism.selectedIndexes();
|
||||
QCOMPARE(mil.size(), 1);
|
||||
QCOMPARE(mil.first(), mi);
|
||||
|
||||
toggleProxy->setSourceModel(model2);
|
||||
toggleProxy.setSourceModel(&model2);
|
||||
// No crash, it's good news!
|
||||
QVERIFY(ism.selection().isEmpty());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user