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.8 6.5 5.15
Change-Id: Ide305dde7934747dbc3acdb49f5a75e98563828c
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
(cherry picked from commit 45f317fba09e98c1fb5f0456ce6309d59d1161cc)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-04-03 14:05:41 +02:00 committed by Qt Cherry-pick Bot
parent f6d8388455
commit 389dab064e

View File

@ -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<QGraphicsWidget>(nullptr, Qt::Window);
QGraphicsGridLayout *layout = new QGraphicsGridLayout(form.get());
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
RectWidget *w1 = new RectWidget;