[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.
This commit is contained in:
John Firebaugh
2016-02-18 19:17:09 -08:00
parent 6792d78952
commit e4b2ea0982

View File

@@ -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;
}