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).

Task-number: QTBUG-115264
Change-Id: Ic0e833d7336435e324457f9d9667ee8573a7dafc
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
(cherry picked from commit 65647d54b9)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2023-07-17 17:40:31 +02:00 committed by Qt Cherry-pick Bot
parent db1bf57a29
commit 22d8539016

View File

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