From 45f317fba09e98c1fb5f0456ce6309d59d1161cc Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 3 Apr 2025 14:05:41 +0200 Subject: [PATCH] tst_QGraphicsGridLayout: fix memleak in spanAcrossEmptyRow() The test function created a parent-less QGraphicsWidget on the heap, and didn't otherwise transfer ownership of it to another object, so the object was leaked. The minimal fix is to hold the graphics-widget in a unique_ptr. This requires to change the following line, too (as would the alternative, allocation on the stack), but the rest of the function can stay as-is (unlike with stack allocation, which would require further s/[.]/->/. Amends 4f072e2d3d7e429359ff15a615d02712bff7ee51. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: Ide305dde7934747dbc3acdb49f5a75e98563828c Reviewed-by: Axel Spoerl --- .../qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp index d4f791f979e..b6f73ed74f3 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -3311,8 +3311,8 @@ void tst_QGraphicsGridLayout::spanningItem() void tst_QGraphicsGridLayout::spanAcrossEmptyRow() { - QGraphicsWidget *form = new QGraphicsWidget(0, Qt::Window); - QGraphicsGridLayout *layout = new QGraphicsGridLayout(form); + const auto form = std::make_unique(nullptr, Qt::Window); + QGraphicsGridLayout *layout = new QGraphicsGridLayout(form.get()); layout->setContentsMargins(0, 0, 0, 0); layout->setSpacing(0); RectWidget *w1 = new RectWidget;