Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/desktop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Cambra <claudio.cambra@gmail.com>2022-06-15 13:06:41 +0300
committerClaudio Cambra <claudio.cambra@gmail.com>2022-06-15 13:06:41 +0300
commita9b900d2af95fa7738692bb4516bd20b7f560022 (patch)
tree92e98bfea8c14c271cef8e2d45b73976b60fcdc6
parent0b355dc4c7b3925d25847695a1206276845088da (diff)
Ensure the dispatch source only gets deallocated after the dispatch_source_cancel is donebugfix/finder-sync-crashing
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
-rw-r--r--shell_integration/MacOSX/OwnCloudFinderSync/FinderSyncExt/LocalSocketClient.m13
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;
}