From 0617d177ac9d584ed6e5298e0fbe1a78ea682ce9 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 24 Mar 2025 09:02:38 +0100 Subject: [PATCH] tst_QGraphicsItem: fix memleaks in sceneEventFilter() A view doesn't own the scene it renders, because scenes can be in multiple views. So if the test function doesn't delete `anotherScene`, no-one else does, either. To fix, allocate it on the stack (like `scene`), and not on the heap. Amends the start of the public history. Pick-to: 6.9 6.8 6.5 5.15 Change-Id: I2f0bfc5dfafd68a347553335f5ac5f2d081d56ad Reviewed-by: Friedemann Kleint Reviewed-by: Volker Hilsheimer --- .../graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp index 457884456ee..b2a3708c88f 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsitem/tst_qgraphicsitem.cpp @@ -5002,12 +5002,12 @@ void tst_QGraphicsItem::sceneEventFilter() //Let check if the items are correctly removed from the sceneEventFilters array //to avoid stale pointers. QGraphicsView gv; - QGraphicsScene *anotherScene = new QGraphicsScene; - QGraphicsTextItem *ti = anotherScene->addText("This is a test #1"); + QGraphicsScene anotherScene; + QGraphicsTextItem *ti = anotherScene.addText("This is a test #1"); ti->moveBy(50, 50); - QGraphicsTextItem *ti2 = anotherScene->addText("This is a test #2"); - QGraphicsTextItem *ti3 = anotherScene->addText("This is a test #3"); - gv.setScene(anotherScene); + QGraphicsTextItem *ti2 = anotherScene.addText("This is a test #2"); + QGraphicsTextItem *ti3 = anotherScene.addText("This is a test #3"); + gv.setScene(&anotherScene); gv.show(); QVERIFY(QTest::qWaitForWindowExposed(&gv)); ti->installSceneEventFilter(ti2);