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 <axel.spoerl@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 284283c5b286a5265d8408b543de8314f7b1aa47)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-24 08:58:55 +01:00 committed by Qt Cherry-pick Bot
parent 5b4e57778a
commit 2cb473b266

View File

@ -3047,13 +3047,14 @@ void tst_QGraphicsItem::mapRectFromToParent()
QFETCH(QRectF, inputRect);
QFETCH(QRectF, outputRect);
QGraphicsRectItem *rect = new QGraphicsRectItem;
std::unique_ptr<QGraphicsRectItem> rectParent; // keep this first
const auto rect = std::make_unique<QGraphicsRectItem>();
rect->setPos(pos);
rect->setTransform(transform);
if (parent) {
QGraphicsRectItem *rectParent = new QGraphicsRectItem;
rect->setParentItem(rectParent);
rectParent = std::make_unique<QGraphicsRectItem>();
rect->setParentItem(rectParent.get());
rectParent->setPos(parentPos);
rectParent->setTransform(parentTransform);
}