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.

Pick-to: 6.8
Change-Id: I9670041273ec8f7bb53108cbaf816e895225cf02
Reviewed-by: Tor Arne Vestbø <tor.arne.vestbo@qt.io>
This commit is contained in:
Nils Petter Skålerud 2024-10-30 13:48:35 +01:00 committed by Tor Arne Vestbø
parent f663a08f20
commit 05b4b1e125

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