Fix UB (reference to local variable leaving scope) in runOnAndroidMainThread()
The QAndroidApplication::runOnAndroidMainThread() function creates a task on QThreadPool::globalInstance() to wait for a timeout and cancel the QFuture representing the task. It does so by passing a lambda to QThreadPool::start(std::function) that captures the future, a local variable, by reference. This is UB when the lambda is ever executed, because the local stack variable's lifetime will have ended. To fix, simply capture the future by value, not by reference. Since QFuture::cancel() is not const, we need to make the lambda mutable. Fixes: QTBUG-109586 Pick-to: 6.5 6.4 6.2 Change-Id: Icacfb0dc76bcd3a145f90126f535e7c0f4b5ef6a Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
This commit is contained in:
parent
b6fdf34dfc
commit
3642d5680d
@ -166,7 +166,7 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
|
||||
promise->start();
|
||||
|
||||
if (!timeout.isForever()) {
|
||||
QThreadPool::globalInstance()->start([=, &future]() {
|
||||
QThreadPool::globalInstance()->start([=]() mutable {
|
||||
QEventLoop loop;
|
||||
QTimer::singleShot(timeout.remainingTime(), &loop, [&]() {
|
||||
future.cancel();
|
||||
|
Loading…
x
Reference in New Issue
Block a user