From 4a9782f6285a5726ba946efdb621e61c4be1a658 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Fri, 28 Mar 2025 09:16:34 +0100 Subject: [PATCH] tst_QGraphicsWidget: fix memleak in implicitMouseGrabber() If a QGraphicsItem is removed from a QGraphicsScene, it also gets un-parent-ed, and the caller of removeItem() is responsible for deleting the item henceforth. The test function neglected that, leaking the object. To fix, use a scope-guard to defer deletion of the object to the exit from the test function. This is the minimally-invasive fix. Amends the start of the public history. Pick-to: 6.8 6.5 5.15 Change-Id: Ie4f9be232674bba583f4a59908e42de096930136 Reviewed-by: Axel Spoerl (cherry picked from commit 156bd559231f06136bc368236675688b3c93d02a) Reviewed-by: Qt Cherry-pick Bot --- .../widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp index 3a3753d72b7..32c44b3fd2b 100644 --- a/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicswidget/tst_qgraphicswidget.cpp @@ -2290,6 +2290,7 @@ void tst_QGraphicsWidget::implicitMouseGrabber() QCOMPARE(widget2UngrabEventSpy.count(), 0); scene.removeItem(widget); + const auto reaper = qScopeGuard([=] { delete widget; }); QCOMPARE(widgetUngrabEventSpy.count(), 4); QCOMPARE(scene.mouseGrabberItem(), nullptr); }