[Sandbox Broker] Fix deadlock and crash
The crash was because we weren't copying the results array before iterating over it, and the deadlock was because this was forced to go through the main thread, rather than going through its calling thread, which could lock up if the main thread was busy working with the Sandbox Broker object. Signed-off-by: Christopher Snowhill <kode54@gmail.com>lastfm
parent
ec91f61403
commit
431849414f
|
@ -142,18 +142,9 @@ static SandboxBroker *kSharedSandboxBroker = nil;
|
|||
return YES;
|
||||
}
|
||||
|
||||
static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_block_t block) {
|
||||
if(dispatch_queue_get_label(queue) == dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL)) {
|
||||
block();
|
||||
} else {
|
||||
dispatch_sync(queue, block);
|
||||
}
|
||||
}
|
||||
|
||||
- (SandboxEntry *)recursivePathTest:(NSURL *)url {
|
||||
__block SandboxEntry *ret = nil;
|
||||
SandboxEntry *ret = nil;
|
||||
|
||||
dispatch_sync_reentrant(dispatch_get_main_queue(), ^{
|
||||
NSPersistentContainer *pc = [SandboxBroker sharedPersistentContainer];
|
||||
|
||||
NSSortDescriptor *sortDescriptor = [NSSortDescriptor sortDescriptorWithKey:@"path.length" ascending:NO];
|
||||
|
@ -171,11 +162,10 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc
|
|||
SandboxEntry *entry = [[SandboxEntry alloc] initWithToken:token];
|
||||
|
||||
ret = entry;
|
||||
return;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
if(ret) {
|
||||
BOOL isStale;
|
||||
|
|
Loading…
Reference in New Issue