From e01449014262cb250a89be420c6bb74498dd3573 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Wed, 26 Mar 2025 21:54:54 +0100 Subject: [PATCH] tst_QAbstractScrollArea: fix memleak in task214488_layoutDirection() QCoreApplication::sendEvent() does not take ownership of the event, postEvent() does, so this test function leaked the QKeyEvent it created on the heap. Fix by creating it on the stack instead. Add a scope to limit the lifetime of the event object to just the sendEvent() call. Amends the start of the public history. This doesn't completely make the test asan-clean, it still suffers from the QScroller::grabGesture() leak (QTBUG-135055). Pick-to: 6.8 6.5 5.15 Change-Id: I8c93e03b2ea919ab80a1d508f008853779eb89af Reviewed-by: Axel Spoerl (cherry picked from commit 0e314d34340b65f88ba5d0e6f04f844813188281) Reviewed-by: Qt Cherry-pick Bot --- .../widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp index f91d9846562..7cd01838df8 100644 --- a/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp +++ b/tests/auto/widgets/widgets/qabstractscrollarea/tst_qabstractscrollarea.cpp @@ -318,7 +318,10 @@ void tst_QAbstractScrollArea::task214488_layoutDirection() scrollArea.setLayoutDirection(dir); int refValue = hbar->value(); - qApp->sendEvent(&scrollArea, new QKeyEvent(QEvent::KeyPress, key, Qt::NoModifier)); + { + QKeyEvent ke(QEvent::KeyPress, key, Qt::NoModifier); + qApp->sendEvent(&scrollArea, &ke); + } QVERIFY(lessThan ? (hbar->value() < refValue) : (hbar->value() > refValue)); }