From 4fe022c40865184b2ba874d11b26f9ac8d5a53d6 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 2 Apr 2025 21:08:41 +0200 Subject: [PATCH] tst_QGraphicsGridLayout: fix memory leaks in columnCount() The populateLayout() function adds parent-less QGraphicsWidgets (RectItems) to the layout. If the layout had a graphics-widget parent, it would reparent the items added to it onto the parent. But it didn't, so it didn't. Therefore, the last part of the test function (as denoted by the re-creation of `layout`) leaked a lot of items, including `layout`. To fix, give the layout the existing graphics-widget parent. Then the layout itself isn't leaked anymore, either. Amends the start of the public history. Essentially the same commit for columnCount() that b9836518a367a31a48027a5bf81c4973b847b442 was for rowCount(). Pick-to: 6.8 6.5 5.15 Change-Id: Ic38dfccfa41049d96eb0cf5811271ac17f2b1f91 Reviewed-by: Axel Spoerl (cherry picked from commit d21434d1876fc778aa5dea6696b145bd6d86d03c) Reviewed-by: Qt Cherry-pick Bot --- .../graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index a16a857aaff..0a02665dfcd 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -606,6 +606,7 @@ void tst_QGraphicsGridLayout::columnCount() // ### Talk with Jasmin. Not sure if removeAt() should adjust columnCount(). widget->setLayout(0); layout = new QGraphicsGridLayout(); + widget->setLayout(layout); populateLayout(layout, 3, 2, hasHeightForWidth); QCOMPARE(layout->columnCount(), 3); layout->removeAt(5);