From a6ffdfec980efb32858c9b4984fd686372f1197e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20Petter=20Ska=CC=8Alerud?= Date: Wed, 30 Oct 2024 13:48:35 +0100 Subject: [PATCH] Darwin, permissions: Fix crash caused by callback going out of scope MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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ø (cherry picked from commit 05b4b1e1250843155d91c929b25d8a8e188315fa) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/platform/darwin/qdarwinpermissionplugin.mm | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/corelib/platform/darwin/qdarwinpermissionplugin.mm b/src/corelib/platform/darwin/qdarwinpermissionplugin.mm index b6c0cbe777f..755e97c0180 100644 --- a/src/corelib/platform/darwin/qdarwinpermissionplugin.mm +++ b/src/corelib/platform/darwin/qdarwinpermissionplugin.mm @@ -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