From a6f082df9bc3d04c06fa42077699afc2e07464bb Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 2 Apr 2025 21:27:54 +0200 Subject: [PATCH] tst_QGraphicsGridLayout: fix memleaks in addItem() Both `layout` and `wid` were created without parents, and not otherwise added to objects that would take their ownership; only `layout` was explicitly deleted at the end of the function, `wid` was leaked. The usual solution, giving them a stack-allocated graphics-widget as parent that will delete them, doesn't work here, because the layout does refuse to add the widget in some test rows. Since there are no checks in-between the allocation and de-allocation (this test is only checking for expected warning messages), do the minimal fix and explicitly delete `wid`, as it was already done for `layout`. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: I5c7356ac93c04d648eb31888105b480791fbe155 Reviewed-by: Axel Spoerl (cherry picked from commit b518a385ad03c3b199f4704088d688b9bf1f3cc6) 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 fec0cb0a158..49aaffe6511 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsgridlayout/tst_qgraphicsgridlayout.cpp @@ -419,6 +419,7 @@ void tst_QGraphicsGridLayout::addItem() } layout->addItem(wid, row, column, rowSpan, columnSpan, alignment); + delete wid; delete layout; }