From fdcf54062cfd372d528948da4637b98b403e174e Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 24 Mar 2025 15:55:47 +0100 Subject: [PATCH] tst_QGraphicsScene: fix memleak in taskQTBUG_5904_crashWithDeviceCoordinateCache() The test had it the wrong way around: it deleted the QWidget it had added to the QGraphicsScene, which thus becomes the widget's owner, but left the scene itself undeleted, leaking it and all the items (but not the widget ;-)). Create the scene on the stack, so it's deleted by the compiler, and release() the widget into the scene.addWidget() call. Since QScopedPointer::take() is deprecated, port to std::unique_ptr. Amends the start of the public history. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: Idbf821a35a7db802a68923fc09b185ddc3181245 Reviewed-by: Volker Hilsheimer Reviewed-by: Friedemann Kleint --- .../graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp index 3e8b3401370..acb7824cc7f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsscene/tst_qgraphicsscene.cpp @@ -4401,17 +4401,17 @@ void tst_QGraphicsScene::taskQTBUG_5904_crashWithDeviceCoordinateCache() void tst_QGraphicsScene::taskQT657_paintIntoCacheWithTransparentParts() { // Test using DeviceCoordinateCache and opaque item - QScopedPointer w(new QWidget); + auto w = std::make_unique(); w->setPalette(QColor(0, 0, 255)); w->setGeometry(0, 0, 50, 50); - QGraphicsScene *scene = new QGraphicsScene(); + QGraphicsScene scene; CustomView view; view.resize(m_testSize); view.setWindowTitle(QTest::currentTestFunction()); - view.setScene(scene); + view.setScene(&scene); - QGraphicsProxyWidget *proxy = scene->addWidget(w.data()); + QGraphicsProxyWidget *proxy = scene.addWidget(w.release()); proxy->setCacheMode(QGraphicsItem::DeviceCoordinateCache); proxy->setTransform(QTransform().rotate(15), true);