From 2cb473b266aa1e9932430282c1fbb572b290b8bd Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 24 Mar 2025 08:58:55 +0100 Subject: [PATCH] tst_QGraphicsItem: fix memory leaks in mapRectFromToParent() The items were not added to any scene, so nothing ever deleted them. Hold them in unique_ptr, taking care to delete the parent, if any, last, even though it was created after its child. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: I9980530efb3386e15b81232e526a1d8d3bb3c36d Reviewed-by: Axel Spoerl Reviewed-by: Friedemann Kleint (cherry picked from commit 284283c5b286a5265d8408b543de8314f7b1aa47) Reviewed-by: Qt Cherry-pick Bot --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index f01031db2c5..457884456ee 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -3047,13 +3047,14 @@ void tst_QGraphicsItem::mapRectFromToParent() QFETCH(QRectF, inputRect); QFETCH(QRectF, outputRect); - QGraphicsRectItem *rect = new QGraphicsRectItem; + std::unique_ptr rectParent; // keep this first + const auto rect = std::make_unique(); rect->setPos(pos); rect->setTransform(transform); if (parent) { - QGraphicsRectItem *rectParent = new QGraphicsRectItem; - rect->setParentItem(rectParent); + rectParent = std::make_unique(); + rect->setParentItem(rectParent.get()); rectParent->setPos(parentPos); rectParent->setTransform(parentTransform); }