tst_QSortFilterProxyModel: fix mem-leaks II: sortStable()

Like in 9f8449a054, for
doubleProxySelectionSetSourceModel(), the sortStable() test also
leaked _everything_. Fix in the same way, by allocating model and view
on the stack intead of the heap.

With this patch, tst_QSortFilterProxyModel is now asan-, but not
ubsan-clean (and, because of
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110704, asan still
reports a leak in cp-demangle.c, which should be™ gone once we fix the
rest of QTBUG-99563).

Pick-to: 6.6 6.5 6.2 5.15
Task-number: QTBUG-115264
Change-Id: Ic0e833d7336435e324457f9d9667ee8573a7dafc
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
This commit is contained in:
Marc Mutz 2023-07-17 17:40:31 +02:00
parent b3930b03cd
commit 65647d54b9

View File

@ -2806,7 +2806,7 @@ void tst_QSortFilterProxyModel::sortColumnTracking2()
void tst_QSortFilterProxyModel::sortStable()
{
QStandardItemModel* model = new QStandardItemModel(5, 2);
QStandardItemModel model(5, 2);
for (int r = 0; r < 5; r++) {
const QString prefix = QLatin1String("Row:") + QString::number(r) + QLatin1String(", Column:");
for (int c = 0; c < 2; c++) {
@ -2815,24 +2815,24 @@ void tst_QSortFilterProxyModel::sortStable()
QStandardItem* child = new QStandardItem(QLatin1String("Item ") + QString::number(i));
item->appendRow( child );
}
model->setItem(r, c, item);
model.setItem(r, c, item);
}
}
model->setHorizontalHeaderItem( 0, new QStandardItem( "Name" ));
model->setHorizontalHeaderItem( 1, new QStandardItem( "Value" ));
model.setHorizontalHeaderItem( 0, new QStandardItem( "Name" ));
model.setHorizontalHeaderItem( 1, new QStandardItem( "Value" ));
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(model);
filterModel->setSourceModel(model);
QSortFilterProxyModel *filterModel = new QSortFilterProxyModel(&model);
filterModel->setSourceModel(&model);
QTreeView *view = new QTreeView;
view->setModel(filterModel);
QTreeView view;
view.setModel(filterModel);
QModelIndex firstRoot = filterModel->index(0,0);
view->expand(firstRoot);
view->setSortingEnabled(true);
view.expand(firstRoot);
view.setSortingEnabled(true);
view->model()->sort(1, Qt::DescendingOrder);
view.model()->sort(1, Qt::DescendingOrder);
QVariant lastItemData =filterModel->index(2,0, firstRoot).data();
view->model()->sort(1, Qt::DescendingOrder);
view.model()->sort(1, Qt::DescendingOrder);
QCOMPARE(lastItemData, filterModel->index(2,0, firstRoot).data());
}