From 1c22374eac69fb2f95b3f6a60e6bfed449508af0 Mon Sep 17 00:00:00 2001 From: John Firebaugh Date: Wed, 2 May 2018 12:34:50 -0700 Subject: [PATCH] [ios, macos] Avoid implicit capture of MBGLOfflineRegionObserver this pointer MBGLOfflineRegionObserver is owned by the offline database thread, and might be destroyed by the time the dispatch_async completes. Instead of implicitly capturing this, capture a copy of the MBGLOfflinePack weak pointer. --- platform/darwin/src/MGLOfflinePack.mm | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/platform/darwin/src/MGLOfflinePack.mm b/platform/darwin/src/MGLOfflinePack.mm index 60a7b5553..5e555d425 100644 --- a/platform/darwin/src/MGLOfflinePack.mm +++ b/platform/darwin/src/MGLOfflinePack.mm @@ -227,19 +227,22 @@ NSError *MGLErrorFromResponseError(mbgl::Response::Error error) { @end void MBGLOfflineRegionObserver::statusChanged(mbgl::OfflineRegionStatus status) { + __weak MBGLOfflinePack *_pack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack offlineRegionStatusDidChange:status]; + [_pack offlineRegionStatusDidChange:status]; }); } void MBGLOfflineRegionObserver::responseError(mbgl::Response::Error error) { + __weak MBGLOfflinePack *_pack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack didReceiveError:MGLErrorFromResponseError(error)]; + [_pack didReceiveError:MGLErrorFromResponseError(error)]; }); } void MBGLOfflineRegionObserver::mapboxTileCountLimitExceeded(uint64_t limit) { + __weak MBGLOfflinePack *_pack = pack; dispatch_async(dispatch_get_main_queue(), ^{ - [pack didReceiveMaximumAllowedMapboxTiles:limit]; + [_pack didReceiveMaximumAllowedMapboxTiles:limit]; }); }