From 3295e7d52b7671c5e9a9a3b245f79146350496ac 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 rowCount() The populateLayoutWithSpansAndHoles() 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. Pick-to: 6.8 6.5 5.15 Change-Id: I063c0e3336d943a35592fa62a5d16cbddb6b920e Reviewed-by: Axel Spoerl (cherry picked from commit b9836518a367a31a48027a5bf81c4973b847b442) 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 9451a72b5ef..7145d8e678c 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -1211,6 +1211,7 @@ void tst_QGraphicsGridLayout::rowCount() // with spans and holes... widget->setLayout(0); layout = new QGraphicsGridLayout(); + widget->setLayout(layout); populateLayoutWithSpansAndHoles(layout, hasHeightForWidth); QCOMPARE(layout->rowCount(), 2); QCOMPARE(layout->columnCount(), 3);