From 79bd27a82bb3a9d6677c5f1f24b1da7dc1bb4d41 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 6 Jan 2025 15:14:36 +0100 Subject: [PATCH] CompactContinuation: make sure what is being deleted by runObj A lambda creates a struct with a function-call operator. So use of 'this' in a lambda body is always a bit ambiguous (the outer object? Or the lambda itself? even though C++ defines it unabiguously to the former). Use a named capture variable instead of 'this' to make it obvious what is being deleted. Amends 699162c6fa6121cc496338f1d8d6e1b4287f7760. Change-Id: I48d82d788d495bac43c6adb114dfdd95a8dd0d1f Reviewed-by: Ivan Solovev (cherry picked from commit 21811161c9109c28da70b7bb9b28df33fa9b7766) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/thread/qfuture_impl.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 088d280e8fe..2f709a56621 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -304,9 +304,9 @@ public: : Storage{std::forward(func)}, promise(std::move(p)), parentFuture(f), threadPool(pool), type(Type::Async) { - runObj = QRunnable::create([this] { - this->runFunction(); - delete this; + runObj = QRunnable::create([continuation = this] { + continuation->runFunction(); + delete continuation; }); runObj->setAutoDelete(false); }