Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,12 @@ - (instancetype) initWithStoreDirectory:(NSString *) storeDirectory dataEncrypto

// Gets current number of events stored.
self.eventCountMutex = [[NSObject alloc] init];
self.numStoredEvents = 0;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.storeDirectory error:nil];
if (files) {
self.numStoredEvents = files.count;
@synchronized (self.eventCountMutex) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You just created the object you synchronize on at line 71, so how will it keep other threads out?
Should you do @synchronized ([self class]) instead?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or use a static member:

static NSObject *initMutex;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
    initMutex = [[NSObject alloc] init];
});

@synchronized (initMutex) {
    // initialization code
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah. Good point. Let me look at what the SApp did again.

self.numStoredEvents = 0;
NSArray *files = [[NSFileManager defaultManager] contentsOfDirectoryAtPath:self.storeDirectory error:nil];
if (files) {
self.numStoredEvents = files.count;
}
}
}
return self;
Expand Down Expand Up @@ -198,7 +200,11 @@ - (void) deleteAllEvents {
}

- (BOOL) shouldStoreEvent {
return (self.isLoggingEnabled && (self.numStoredEvents < self.maxEvents));
BOOL result;
@synchronized (self.eventCountMutex) {
result = (self.isLoggingEnabled && (self.numStoredEvents < self.maxEvents));
}
return result;
}

- (BOOL) isLoggingEnabled {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,15 @@ - (void)kickOffIDPInitiatedLoginFlowForSP:(SFSDKSPConfig *)config statusUpdate:(
}

- (BOOL)loginWithCompletion:(SFUserAccountManagerSuccessCallbackBlock)completionBlock failure:(SFUserAccountManagerFailureCallbackBlock)failureBlock {
BOOL result = NO;
__block BOOL result = NO;
if (![NSThread isMainThread]) {
dispatch_async(dispatch_get_main_queue(), ^{
result = [self loginWithCompletion:completionBlock failure:failureBlock];
});

return result;
}

for (UIScene *scene in [SFApplicationHelper sharedApplication].connectedScenes) {
result |= [self loginWithCompletion:completionBlock failure:failureBlock scene:scene];
}
Expand Down Expand Up @@ -1219,7 +1227,11 @@ - (BOOL)handleAdvancedAuthURL:(NSURL *)advancedAuthURL options:(NSDictionary *)o

#pragma mark Account management
- (NSArray *)allUserAccounts {
return [self.userAccountMap allValues];
NSArray *accounts = nil;
[_accountsLock lock];
accounts = [self.userAccountMap allValues];
[_accountsLock unlock];
return accounts;
}

- (NSArray *)allUserIdentities {
Expand Down
Loading