From 02fb66f8a53499d4923f0a25d68b35b38c5f1523 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 27 Mar 2025 22:07:02 +0100 Subject: [PATCH] tst_QGraphicsProxyWidget: fix memleak in touchEventPropagation() The result of QTest::createTouchDevice() needs to be deleted by the caller. The test function didn't, so leaked the object. Fix by holding it in unique_ptr. Amends 1ecf2212fae176b78c9951a37df9e33eb24d4f2d. Not picking to 5.15, because the cherry-pick of 1ecf2212fae176b78c9951a37df9e33eb24d4f2d to 5.15 was abandoned. Pick-to: 6.8 6.5 Change-Id: I649357466a51e02d669b114bdfa0746bfa09fe34 Reviewed-by: Axel Spoerl (cherry picked from commit 01ee8fd7b5c93cffaeb8624ed87f5dee36e9e5e6) Reviewed-by: Qt Cherry-pick Bot --- .../tst_qgraphicsproxywidget.cpp | 22 +++++++++---------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp index c7bb59a1815..28002a3232e 100644 --- a/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp +++ b/tests/auto/widgets/graphicsview/qgraphicsproxywidget/tst_qgraphicsproxywidget.cpp @@ -3926,7 +3926,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() } eventSpy; qApp->installEventFilter(&eventSpy); - auto *touchDevice = QTest::createTouchDevice(); + const std::unique_ptr touchDevice{QTest::createTouchDevice()}; const QPointF simpleCenter = simpleProxy->geometry().center(); // On systems without double conversion we might get different rounding behavior. @@ -3940,7 +3940,7 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() }; // verify that the embedded widget gets the correctly translated event - QTest::touchEvent(&view, touchDevice).press(0, simpleCenter.toPoint()); + QTest::touchEvent(&view, touchDevice.get()).press(0, simpleCenter.toPoint()); // window, viewport, scene, simpleProxy, simpleWidget QCOMPARE(eventSpy.count(), 5); QCOMPARE(eventSpy.at(0).receiver, view.windowHandle()); @@ -3975,9 +3975,9 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() // Single touch point to nested widget not accepting event. // Event should bubble up and translate correctly, TouchUpdate and TouchEnd events // stop at the window since nobody accepted the TouchBegin. A mouse event will be generated. - QTest::touchEvent(&view, touchDevice).press(0, pb1TouchPos); - QTest::touchEvent(&view, touchDevice).move(0, pb1TouchPos + QPoint(1, 1)); - QTest::touchEvent(&view, touchDevice).release(0, pb1TouchPos + QPoint(1, 1)); + QTest::touchEvent(&view, touchDevice.get()).press(0, pb1TouchPos); + QTest::touchEvent(&view, touchDevice.get()).move(0, pb1TouchPos + QPoint(1, 1)); + QTest::touchEvent(&view, touchDevice.get()).release(0, pb1TouchPos + QPoint(1, 1)); // ..., formProxy, pushButton1, formWidget, window, window QCOMPARE(eventSpy.count(), 8); QCOMPARE(eventSpy.at(3).receiver, formProxy); // formProxy dispatches to the right subwidget @@ -4002,9 +4002,9 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() clickedSpy.clear(); // Single touch point to nested widget accepting event. - QTest::touchEvent(&view, touchDevice).press(0, tw1TouchPos); - QTest::touchEvent(&view, touchDevice).move(0, tw1TouchPos + QPoint(5, 5)); - QTest::touchEvent(&view, touchDevice).release(0, tw1TouchPos + QPoint(5, 5)); + QTest::touchEvent(&view, touchDevice.get()).press(0, tw1TouchPos); + QTest::touchEvent(&view, touchDevice.get()).move(0, tw1TouchPos + QPoint(5, 5)); + QTest::touchEvent(&view, touchDevice.get()).release(0, tw1TouchPos + QPoint(5, 5)); // Press: ..., formProxy, touchWidget1 (5) // Move: window, touchWidget1 (2) // Release: window, touchWidget1 (2) @@ -4035,17 +4035,17 @@ void tst_QGraphicsProxyWidget::touchEventPropagation() touchWidget2->installEventFilter(&eventSpy); // multi-touch to different widgets, some do and some don't accept the event - QTest::touchEvent(&view, touchDevice) + QTest::touchEvent(&view, touchDevice.get()) .press(0, pb1TouchPos) .press(1, tw1TouchPos) .press(2, pb2TouchPos) .press(3, tw2TouchPos); - QTest::touchEvent(&view, touchDevice) + QTest::touchEvent(&view, touchDevice.get()) .move(0, pb1TouchPos + QPoint(1, 1)) .move(1, tw1TouchPos + QPoint(1, 1)) .move(2, pb2TouchPos + QPoint(1, 1)) .move(3, tw2TouchPos + QPoint(1, 1)); - QTest::touchEvent(&view, touchDevice) + QTest::touchEvent(&view, touchDevice.get()) .release(0, pb1TouchPos + QPoint(1, 1)) .release(1, tw1TouchPos + QPoint(1, 1)) .release(2, pb2TouchPos + QPoint(1, 1))