summaryrefslogtreecommitdiff
path: root/platform
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2016-02-18 19:17:09 -0800
committerJohn Firebaugh <john.firebaugh@gmail.com>2016-02-19 10:11:27 -0800
commite4b2ea0982d3eb76ebb75754bbcb9059a018ca6b (patch)
tree2e78cc97a9a546d0aabaafcc9324b6b42fe0ce42 /platform
parent6792d789521a104f78a9a702672672387831d78c (diff)
downloadqtlocation-mapboxgl-e4b2ea0982d3eb76ebb75754bbcb9059a018ca6b.tar.gz
[ios, osx] Don't delete a mutex with an active lock
The lock is in place to enforce that `async` is not accessed if the request has been, cancelled. Therefore it's not necessary to hold the lock beyond setting cancelled to true, and in fact it's unsafe to so: if this is the last remaining shared reference, `delete this` will destroy the mutex. If the lock was held, it would then be orphaned.
Diffstat (limited to 'platform')
-rw-r--r--platform/darwin/src/http_request_nsurl.mm11
1 files changed, 9 insertions, 2 deletions
diff --git a/platform/darwin/src/http_request_nsurl.mm b/platform/darwin/src/http_request_nsurl.mm
index 5684afec32..e58441e4d2 100644
--- a/platform/darwin/src/http_request_nsurl.mm
+++ b/platform/darwin/src/http_request_nsurl.mm
@@ -153,8 +153,15 @@ void HTTPNSURLRequest::cancel() {
task = nullptr;
}
- std::lock_guard<std::mutex> lock(cancelled->second);
- cancelled->first = true;
+ {
+ std::lock_guard<std::mutex> lock(cancelled->second);
+ cancelled->first = true;
+ }
+
+ // The lock is in place to enforce that `async` is not accessed if the request has been
+ // cancelled. Therefore it's not necessary to hold the lock beyond setting cancelled to
+ // true, and in fact it's unsafe to so: if this is the last remaining shared reference,
+ // `delete this` will destroy the mutex. If the lock was held, it would then be orphaned.
delete this;
}