From fadb33ece4067ec18ac4a17a28ac62aadab205e0 Mon Sep 17 00:00:00 2001 From: Michael Kurz Date: Wed, 27 Nov 2024 13:11:35 +0100 Subject: [PATCH] MRS-2850 Crash if listen/cancel is executed in quick succession The onDidAuthorizationChanged is executed by iOS somewhen afer CLLocationManager is created in onListenWithArguments. If the the subscription is canceled in the meantime _eventSink (onCancelWithArguments) is set to nil leading to accessing _eventSink when already nil (BAD_ACCESS crash). --- .../Classes/Handlers/LocationServiceStreamHandler.m | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/geolocator_apple/ios/Classes/Handlers/LocationServiceStreamHandler.m b/geolocator_apple/ios/Classes/Handlers/LocationServiceStreamHandler.m index ac6e8ff4..208ef6ca 100644 --- a/geolocator_apple/ios/Classes/Handlers/LocationServiceStreamHandler.m +++ b/geolocator_apple/ios/Classes/Handlers/LocationServiceStreamHandler.m @@ -37,10 +37,12 @@ - (void)locationManager:(CLLocationManager *)manager didChangeAuthorizationStatu dispatch_async(dispatch_get_global_queue( DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ BOOL isEnabled = [CLLocationManager locationServicesEnabled]; dispatch_async(dispatch_get_main_queue(), ^(void) { - if (isEnabled) { - self->_eventSink([NSNumber numberWithInt:(ServiceStatus)enabled]); - } else { - self->_eventSink([NSNumber numberWithInt:(ServiceStatus)disabled]); + if (_eventSink != nil) { + if (isEnabled) { + self->_eventSink([NSNumber numberWithInt:(ServiceStatus) enabled]); + } else { + self->_eventSink([NSNumber numberWithInt:(ServiceStatus) disabled]); + } } }); });