diff options
author | Matthieu Gallien <matthieu_gallien@yahoo.fr> | 2022-07-01 17:59:44 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-01 17:59:44 +0300 |
commit | eb5c589501e9d52033345bc0fc1e5ac4bf4988d1 (patch) | |
tree | 9c6cb4575c8c4a2dd2ac8fdd8e210c96af421d7f | |
parent | da4a9aeadf17dc747e6280441450ca535e80e28d (diff) | |
parent | c5a07d7f4e3758fc0ba384ee46b95750c05f58d8 (diff) |
Merge pull request #4696 from nextcloud/backport/4643/stable-3.5v3.5.2
[stable-3.5] Ensure the dispatch source only gets deallocated after the dispatch_source_cancel is done, avoiding crashing of the Finder Sync Extension on macOS
-rw-r--r-- | shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m b/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m index 37c39cc7b..ab43a5df2 100644 --- a/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m +++ b/shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m @@ -139,11 +139,24 @@ NSLog(@"Closing connection."); if(self.readSource) { + // Since dispatch_source_cancel works asynchronously, if we deallocate the dispatch source here then we can + // cause a crash. So instead we strongly hold a reference to the read source and deallocate it asynchronously + // with the handler. + __block dispatch_source_t previousReadSource = self.readSource; + dispatch_source_set_cancel_handler(self.readSource, ^{ + previousReadSource = nil; + }); dispatch_source_cancel(self.readSource); + // The readSource is still alive due to the other reference and will be deallocated by the cancel handler self.readSource = nil; } if(self.writeSource) { + // Same deal with the write source + __block dispatch_source_t previousWriteSource = self.writeSource; + dispatch_source_set_cancel_handler(self.writeSource, ^{ + previousWriteSource = nil; + }); dispatch_source_cancel(self.writeSource); self.writeSource = nil; } |