Darwin, permissions: Fix crash caused by callback going out of scope

Change 0990bd49407aac4f96acf78761af1070ff934215 introduced a runtime
crash where callback object was being referenced rather than copied,
causing it to go out of scope and causing a segfault. This patch
captures the callback by copy explicitly.

Change-Id: I9670041273ec8f7bb53108cbaf816e895225cf02
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
(cherry picked from commit 05b4b1e1250843155d91c929b25d8a8e188315fa)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Nils Petter Skålerud 2024-10-30 13:48:35 +01:00 committed by Qt Cherry-pick Bot
parent 3a25183c5d
commit a6ffdfec98

View File

@ -28,7 +28,10 @@ void QDarwinPermissionPlugin::requestPermission(const QPermission &permission, c
return;
}
[m_handler requestPermission:permission withCallback:[&](Qt::PermissionStatus status) {
// QCoreApplication::requestPermission is commonly used with an inline lambda for the
// callback object, meaning it won't be alive when the permission is granted later,
// so make sure to copy the callback object.
[m_handler requestPermission:permission withCallback:[&, callback](Qt::PermissionStatus status) {
// In case the callback comes in on a secondary thread we need to marshal it
// back to the main thread. And if it doesn't, we still want to propagate it
// via an event, to avoid any GCD locks deadlocking the application on iOS