mirror of
https://github.com/nextcloud/desktop.git
synced 2024-11-21 20:45:51 +03:00
Ensure the dispatch source only gets deallocated after the dispatch_source_cancel is done
Signed-off-by: Claudio Cambra <claudio.cambra@gmail.com>
This commit is contained in:
parent
8ce08424ba
commit
a74f9b367d
1 changed files with 13 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue