From f6d83884553bb41ba2a9e5e980ecdb0f44fdead4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 3 Apr 2025 13:58:55 +0200 Subject: [PATCH] tst_QGraphicsGridLayout: fix memleak in removeItem() The test function contains a negative test where we're trying to remove an item that isn't in the layout. Unfortunately, the object we're passing is heap-allocated and has no parent, so was leaked. To fix, pass the existing `widget` as a parent. This doesn't change the test's outcome: Like in QWidget, a graphics-widget is not automatically added to its parent's layout. Amends the start of the public history. Pick-to: 6.6 6.5 5.15 Change-Id: Ic110ea7b93aa0023c0903c776a30dc5c377ce0c5 Reviewed-by: Axel Spoerl (cherry picked from commit 4d0f979610b961e3dd4e86060fc05456c9d1447d) Reviewed-by: Qt Cherry-pick Bot --- .../qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index 1ec739a9f47..fb51c64d7db 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -1111,7 +1111,7 @@ void tst_QGraphicsGridLayout::removeItem() QCOMPARE(l->count(), 4); QTest::ignoreMessage(QtWarningMsg, QString::fromLatin1("QGraphicsGridLayout::removeAt: invalid index -1").toLatin1().constData()); - l->removeItem(new QGraphicsWidget); + l->removeItem(new QGraphicsWidget(widget)); QCOMPARE(l->count(), 4); }