From eba728f1a3984f66a2d813838bc0297151edf6c4 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 24 Mar 2025 15:59:45 +0100 Subject: [PATCH] tst_QGraphicsScene: fix memleaks in taskQTBUG_7863_paintIntoCacheWithTransparentParts() The test function created QGraphicScene objects on the heap, but never deleted them. They were added to a View, yes, but a view doesn't own the scene it renders, so this didn't help. Fix by creating the scenes on the stack instead. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: I939e028dbfd68b216ef67c3773f085ba98817b05 Reviewed-by: Volker Hilsheimer Reviewed-by: Friedemann Kleint (cherry picked from commit d8b79dc1c949cd4cb5472f53545fbdd94f6e5b3b) Reviewed-by: Qt Cherry-pick Bot --- .../qgraphicsscene/tst_qgraphicsscene.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index acb7824cc7f..176d6b67b58 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -4450,13 +4450,13 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() rectItem->setBrush(QColor(0, 0, 255, 125)); rectItem->setParentItem(backItem); - QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsScene scene; CustomView view; view.resize(m_testSize); view.setWindowTitle(QTest::currentTestFunction()); - view.setScene(scene); + view.setScene(&scene); - scene->addItem(backItem); + scene.addItem(backItem); rectItem->setCacheMode(QGraphicsItem::DeviceCoordinateCache); backItem->setTransform(QTransform().rotate(15), true); @@ -4491,13 +4491,13 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 50, 50); rectItem->setBrush(QColor(0, 0, 255)); - QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsScene scene; CustomView view; view.setWindowTitle(QTest::currentTestFunction()); view.resize(m_testSize); - view.setScene(scene); + view.setScene(&scene); - scene->addItem(rectItem); + scene.addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true); @@ -4531,13 +4531,13 @@ void tst_QGraphicsScene::taskQTBUG_7863_paintIntoCacheWithTransparentParts() QGraphicsRectItem *rectItem = new QGraphicsRectItem(0, 0, 50, 50); rectItem->setBrush(QColor(0, 0, 255, 125)); - QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsScene scene; CustomView view; view.setWindowTitle(QTest::currentTestFunction()); view.resize(m_testSize); - view.setScene(scene); + view.setScene(&scene); - scene->addItem(rectItem); + scene.addItem(rectItem); rectItem->setCacheMode(QGraphicsItem::ItemCoordinateCache); rectItem->setTransform(QTransform().rotate(15), true);