Skip to content

Commit 5b3598b

Browse files
committed
- OCClassSettings: avoid race conditions when logging is triggered from OCClassSettings sources
1 parent dacd633 commit 5b3598b

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

ownCloudSDK/Settings/OCClassSettings.m

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,16 +39,23 @@ + (instancetype)sharedSettings
3939
{
4040
static dispatch_once_t onceToken;
4141
static OCClassSettings *sharedClassSettings = nil;
42-
42+
__block BOOL addDefaultSources = NO;
43+
4344
dispatch_once(&onceToken, ^{
4445
sharedClassSettings = [OCClassSettings new];
46+
addDefaultSources = YES;
47+
});
4548

49+
if (addDefaultSources)
50+
{
51+
// Add sources outside dispatch_once, so that calling OCLog / OCClassSettings.sharedSettings will not
52+
// lead to a crash due to a call of dispatch_once from within the same dispatch_once
4653
[sharedClassSettings addSource:[OCClassSettingsFlatSourceManagedConfiguration new]];
4754
[sharedClassSettings addSource:[OCClassSettingsUserPreferences sharedUserPreferences]];
4855
[sharedClassSettings addSource:[OCClassSettingsFlatSourcePostBuild sharedPostBuildSettings]];
4956
[sharedClassSettings addSource:[[OCClassSettingsFlatSourceEnvironment alloc] initWithPrefix:@"oc:"]];
50-
});
51-
57+
}
58+
5259
return(sharedClassSettings);
5360
}
5461

0 commit comments

Comments
 (0)