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 <shawn.rutledge@qt.io>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io>
(cherry picked from commit 49a87936ef50acb1ab7156809bf5f85671d36f24)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-23 22:35:32 +01:00 committed by Qt Cherry-pick Bot
parent f988f8fc30
commit c831210d0b

View File

@ -121,7 +121,7 @@ private slots:
void mouseEventTimestamp();
private:
QPointingDevice *m_touchScreen = QTest::createTouchDevice();
const std::unique_ptr<QPointingDevice> 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<QTouchEvent::TouchPoint>() << 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<QEventPoint>() << 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<QEventPoint>() << 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<QEventPoint>() << 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<QEventPoint>() << 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<QEventPoint>() << touchPoint));
QApplication::sendEvent(sw, &touchEvent5);