From 59b18d07e78be0b57c8bb7c9078e89c686ddf0f3 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Mar 2025 21:09:46 +0100 Subject: [PATCH] tst_QGraphicsLinearLayout: remove remaining memleaks in insertItem() After the QGraphicsWidgets have been dealt with in a previous commit, the last leak in the function is that of 'item'. Fix by holding it in a unique_ptr. Amends the start of the public history. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: I56986139a2b7865cf367bdd25ccde90d5e1c50ca Reviewed-by: Axel Spoerl --- .../tst_qgraphicslinearlayout.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp index f7137b1e12a..e5d61d28be5 100644 --- a/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicslinearlayout/tst_qgraphicslinearlayout.cpp @@ -468,18 +468,18 @@ void tst_QGraphicsLinearLayout::insertItem() for (int i = 0; i < layoutCount; ++i) layout.addItem(new SubQGraphicsLinearLayout); - QGraphicsLayoutItem *item = nullptr; + std::unique_ptr item = nullptr; if (isWidget) - item = new QGraphicsWidget; + item = std::make_unique(); else - item = new SubQGraphicsLinearLayout; + item = std::make_unique(); QSizeF oldSizeHint = layout.sizeHint(Qt::PreferredSize, QSizeF()); - layout.insertItem(insertItemAt, item); + layout.insertItem(insertItemAt, item.get()); QCOMPARE(layout.count(), itemCount + layoutCount + 1); if (insertItemAt >= 0 && (itemCount + layoutCount >= 0)) { - QCOMPARE(layout.itemAt(insertItemAt), item); + QCOMPARE(layout.itemAt(insertItemAt), item.get()); } layout.activate();