From c831210d0bb93575939259c8a11e01a473dd0984 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Sun, 23 Mar 2025 22:35:32 +0100 Subject: [PATCH] tst_QScroller: fix leak of m_touchScreen The result of QTest::createTouchScreen() needs to be deleted by the caller, and this test didn't do that. To fix, put the object into a unique_ptr. Amends 982b70d37db337b2c57a3cfce0f24c3d00a598d6, though the code it replaced seems to have had the same problem. Picking all the way back, since this code hasn't changed in ages, and so conflicts are unlikely. Also, there appears to be a remaining leak in QScroller::grabGesture(), and we don't know, yet, how far we'd pick that one, but verifying it will likely be helped by the test not otherwise leaking. Filed QTBUG-135055 to track the issue. Pick-to: 6.8 6.5 5.15 Task-number: QTBUG-135055 Change-Id: I6ab3402671f768c6a33b682d456145f18629e6cb Reviewed-by: Shawn Rutledge Reviewed-by: Friedemann Kleint (cherry picked from commit 49a87936ef50acb1ab7156809bf5f85671d36f24) Reviewed-by: Qt Cherry-pick Bot --- .../auto/widgets/util/qscroller/tst_qscroller.cpp | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp index b0a01c21be0..8cd4d78aac1 100644 --- a/tests/auto/widgets/util/qscroller/tst_qscroller.cpp +++ b/tests/auto/widgets/util/qscroller/tst_qscroller.cpp @@ -121,7 +121,7 @@ private slots: void mouseEventTimestamp(); private: - QPointingDevice *m_touchScreen = QTest::createTouchDevice(); + const std::unique_ptr m_touchScreen{QTest::createTouchDevice()}; }; /*! \internal @@ -146,7 +146,7 @@ void tst_QScroller::kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint QMutableEventPoint::setGlobalPosition(touchPoint, touchStart); QTouchEvent touchEvent1(QEvent::TouchBegin, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); @@ -161,7 +161,7 @@ void tst_QScroller::kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint QMutableEventPoint::setGlobalPosition(touchPoint, touchUpdate); QMutableEventPoint::setState(touchPoint, QEventPoint::State::Updated); QTouchEvent touchEvent2(QEvent::TouchUpdate, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent2); @@ -185,7 +185,7 @@ void tst_QScroller::kineticScroll(tst_QScrollerWidget *sw, QPointF from, QPoint QMutableEventPoint::setGlobalPosition(touchPoint, touchEnd); QMutableEventPoint::setState(touchPoint, QEventPoint::State::Released); QTouchEvent touchEvent5(QEvent::TouchEnd, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent5); @@ -213,7 +213,7 @@ void tst_QScroller::kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, Q QMutableEventPoint::setScenePosition(touchPoint, touchStart); QMutableEventPoint::setGlobalPosition(touchPoint, touchStart); QTouchEvent touchEvent1(QEvent::TouchBegin, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent1); @@ -225,7 +225,7 @@ void tst_QScroller::kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, Q QMutableEventPoint::setScenePosition(touchPoint, touchUpdate); QMutableEventPoint::setGlobalPosition(touchPoint, touchUpdate); QTouchEvent touchEvent2(QEvent::TouchUpdate, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent2); @@ -238,7 +238,7 @@ void tst_QScroller::kineticScrollNoTest(tst_QScrollerWidget *sw, QPointF from, Q QMutableEventPoint::setScenePosition(touchPoint, touchEnd); QMutableEventPoint::setGlobalPosition(touchPoint, touchEnd); QTouchEvent touchEvent5(QEvent::TouchEnd, - m_touchScreen, + m_touchScreen.get(), Qt::NoModifier, (QList() << touchPoint)); QApplication::sendEvent(sw, &touchEvent5);