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 <axel.spoerl@qt.io>
(cherry picked from commit 0e314d34340b65f88ba5d0e6f04f844813188281)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marc Mutz 2025-03-26 21:54:54 +01:00 committed by Qt Cherry-pick Bot
parent ba9d8cc422
commit e014490142

View File

@ -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));
}