Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

Commit c523391

Browse files
committed
[macos,ios] Fix rare crash when downloading tiles that returned a 404
We were capturing the reference to an object that could go away when the request was canceled. However, the lambda could still be invoked by NSURLSession, creating a race condition with a resulting crash when the response to a tile request was 404 Not Found.
1 parent c763c26 commit c523391

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

platform/darwin/src/http_file_source.mm

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,8 +245,10 @@ void cancel() {
245245
}
246246

247247
[req addValue:impl->userAgent forHTTPHeaderField:@"User-Agent"];
248-
249-
if (resource.kind == mbgl::Resource::Kind::Tile) {
248+
249+
const bool isTile = resource.kind == mbgl::Resource::Kind::Tile;
250+
251+
if (isTile) {
250252
[[MGLNetworkConfiguration sharedManager] startDownloadEvent:url.relativePath type:@"tile"];
251253
}
252254

@@ -322,7 +324,7 @@ void cancel() {
322324

323325
if (responseCode == 200) {
324326
response.data = std::make_shared<std::string>((const char *)[data bytes], [data length]);
325-
} else if (responseCode == 204 || (responseCode == 404 && resource.kind == Resource::Kind::Tile)) {
327+
} else if (responseCode == 204 || (responseCode == 404 && isTile)) {
326328
response.noContent = true;
327329
} else if (responseCode == 304) {
328330
response.notModified = true;

0 commit comments

Comments
 (0)