Skip to content

Commit ad06c60

Browse files
RCNConfigFetch: fix weakSelf/strongSelf usage (#6133)
* RCNConfigFetch: fix weakSelf/strongSelf usage * self->strongSelf * Style * Changelog * Another self to strongSelf * Rename file to match class name and corresponding header RCNFetch.m -> RCNConfigFetch.m
1 parent 16e062c commit ad06c60

File tree

2 files changed

+35
-17
lines changed

2 files changed

+35
-17
lines changed

FirebaseRemoteConfig/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# v4.8.1
2+
- [fixed] Fixed `FirebaseApp.delete()` related crash in `RC Config Fetch`. (#6123)
3+
14
# v4.8.0
25
- [changed] Functionally neutral source reorganization for preliminary Swift Package Manager support. (#6013)
36

FirebaseRemoteConfig/Sources/RCNFetch.m renamed to FirebaseRemoteConfig/Sources/RCNConfigFetch.m

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,11 @@ - (void)fetchConfigWithExpirationDuration:(NSTimeInterval)expirationDuration
131131
FIRRemoteConfigHasDeviceContextChanged(_settings.deviceContext, _options.googleAppID);
132132

133133
__weak RCNConfigFetch *weakSelf = self;
134-
RCNConfigFetch *fetchWithExpirationSelf = weakSelf;
135-
dispatch_async(fetchWithExpirationSelf->_lockQueue, ^{
136-
RCNConfigFetch *strongSelf = fetchWithExpirationSelf;
134+
dispatch_async(_lockQueue, ^{
135+
RCNConfigFetch *strongSelf = weakSelf;
136+
if (strongSelf == nil) {
137+
return;
138+
}
137139

138140
// Check whether we are outside of the minimum fetch interval.
139141
if (![strongSelf->_settings hasMinimumFetchIntervalElapsed:expirationDuration] &&
@@ -216,15 +218,22 @@ - (void)refreshInstallationsTokenWithCompletionHandler:
216218
NSLocalizedDescriptionKey : errorDescription
217219
}]];
218220
}
221+
222+
__weak RCNConfigFetch *weakSelf = self;
219223
FIRInstallationsTokenHandler installationsTokenHandler = ^(
220224
FIRInstallationsAuthTokenResult *tokenResult, NSError *error) {
225+
RCNConfigFetch *strongSelf = weakSelf;
226+
if (strongSelf == nil) {
227+
return;
228+
}
229+
221230
if (!tokenResult || !tokenResult.authToken || error) {
222231
NSString *errorDescription =
223232
[NSString stringWithFormat:@"Failed to get installations token. Error : %@.", error];
224233
FIRLogError(kFIRLoggerRemoteConfig, @"I-RCN000073", @"%@",
225234
[NSString stringWithFormat:@"%@", errorDescription]);
226-
self->_settings.isFetchInProgress = NO;
227-
return [self
235+
strongSelf->_settings.isFetchInProgress = NO;
236+
return [strongSelf
228237
reportCompletionOnHandler:completionHandler
229238
withStatus:FIRRemoteConfigFetchStatusFailure
230239
withError:[NSError errorWithDomain:FIRRemoteConfigErrorDomain
@@ -235,14 +244,19 @@ - (void)refreshInstallationsTokenWithCompletionHandler:
235244
}
236245

237246
// We have a valid token. Get the backing installationID.
238-
__weak RCNConfigFetch *weakSelf = self;
239247
[installations installationIDWithCompletion:^(NSString *_Nullable identifier,
240248
NSError *_Nullable error) {
241249
RCNConfigFetch *strongSelf = weakSelf;
250+
if (strongSelf == nil) {
251+
return;
252+
}
242253

243254
// Dispatch to the RC serial queue to update settings on the queue.
244255
dispatch_async(strongSelf->_lockQueue, ^{
245256
RCNConfigFetch *strongSelfQueue = weakSelf;
257+
if (strongSelfQueue == nil) {
258+
return;
259+
}
246260

247261
// Update config settings with the IID and token.
248262
strongSelfQueue->_settings.configInstallationsToken = tokenResult.authToken;
@@ -337,17 +351,17 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
337351
@"config fetch completed. Error: %@ StatusCode: %ld", (error ? error : @"nil"),
338352
(long)[((NSHTTPURLResponse *)response) statusCode]);
339353

340-
// The fetch has completed.
341-
self->_settings.isFetchInProgress = NO;
342-
343354
RCNConfigFetch *fetcherCompletionSelf = weakSelf;
344-
if (!fetcherCompletionSelf) {
355+
if (fetcherCompletionSelf == nil) {
345356
return;
346-
};
357+
}
358+
359+
// The fetch has completed.
360+
fetcherCompletionSelf->_settings.isFetchInProgress = NO;
347361

348362
dispatch_async(fetcherCompletionSelf->_lockQueue, ^{
349363
RCNConfigFetch *strongSelf = weakSelf;
350-
if (!strongSelf) {
364+
if (strongSelf == nil) {
351365
return;
352366
}
353367

@@ -464,8 +478,8 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
464478
// Add the fetched config to the database.
465479
if (fetchedConfig) {
466480
// Update config content to cache and DB.
467-
[self->_content updateConfigContentWithResponse:fetchedConfig
468-
forNamespace:self->_FIRNamespace];
481+
[strongSelf->_content updateConfigContentWithResponse:fetchedConfig
482+
forNamespace:strongSelf->_FIRNamespace];
469483
// Update experiments.
470484
[strongSelf->_experiment
471485
updateExperimentsWithResponse:fetchedConfig[RCNFetchResponseKeyExperimentDescriptions]];
@@ -476,11 +490,12 @@ - (void)fetchWithUserProperties:(NSDictionary *)userProperties
476490

477491
// We had a successful fetch. Update the current eTag in settings if different.
478492
NSString *latestETag = ((NSHTTPURLResponse *)response).allHeaderFields[kETagHeaderName];
479-
if (!self->_settings.lastETag || !([self->_settings.lastETag isEqualToString:latestETag])) {
480-
self->_settings.lastETag = latestETag;
493+
if (!strongSelf->_settings.lastETag ||
494+
!([strongSelf->_settings.lastETag isEqualToString:latestETag])) {
495+
strongSelf->_settings.lastETag = latestETag;
481496
}
482497

483-
[self->_settings updateMetadataWithFetchSuccessStatus:YES];
498+
[strongSelf->_settings updateMetadataWithFetchSuccessStatus:YES];
484499
return [strongSelf reportCompletionOnHandler:completionHandler
485500
withStatus:FIRRemoteConfigFetchStatusSuccess
486501
withError:nil];

0 commit comments

Comments
 (0)