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.9 6.8 6.5 5.15
Change-Id: I8c93e03b2ea919ab80a1d508f008853779eb89af
Reviewed-by: Axel Spoerl <axel.spoerl@qt.io>
This commit is contained in:
Marc Mutz 2025-03-26 21:54:54 +01:00
parent 7cf8b2d030
commit 0e314d3434

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