From 0aabc8f2e9ce1517f5b1b61af61debf4a55136dc Mon Sep 17 00:00:00 2001 From: Nick Cooke <36927374+ncooke3@users.noreply.github.com> Date: Tue, 13 Oct 2026 12:24:12 -0400 Subject: [PATCH] fix: address Objective-C -O1 ARC lifetime issue in GULNetworkURLSession (#255) * fix: address Objective-C -O1 ARC lifetime issue in GULNetworkURLSession * changelog --- CHANGELOG.md | 2 ++ GoogleUtilities/Network/GULNetworkURLSession.m | 8 +++----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2e21704..e38af2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,8 @@ call read `-[NSBundle appStoreReceiptURL]`, which makes a synchronous XPC call to the LaunchServices daemon and could block the calling thread, often the main thread, for seconds. (firebase/firebase-ios-sdk#16726) +- [fixed] Fix an ARC-related deadlock in `GULNetworkURLSession` under -O1 + optimization. (#255) # 8.1.4 - [fixed] `GULMutableDictionary` now ignores a `nil` key (and a `nil` object in diff --git a/GoogleUtilities/Network/GULNetworkURLSession.m b/GoogleUtilities/Network/GULNetworkURLSession.m index e7e31c2..8176a09 100644 --- a/GoogleUtilities/Network/GULNetworkURLSession.m +++ b/GoogleUtilities/Network/GULNetworkURLSession.m @@ -727,7 +727,9 @@ static const void *kGULSessionTrackerKey = &kGULSessionTrackerKey; return; } - GULSessionDeallocTracker *oldTrackerToReleaseOutsideLock = nil; + // Retain the old tracker until the lock is released. If it deallocates inside the lock, + // its -dealloc method will attempt to re-acquire the lock, resulting in a deadlock. + NS_VALID_UNTIL_END_OF_SCOPE GULSessionDeallocTracker *oldTrackerToReleaseOutsideLock = nil; [[self sessionIDToFetcherMapReadWriteLock] lock]; GULNetworkURLSessionWeakHolder *holder = @@ -759,10 +761,6 @@ static const void *kGULSessionTrackerKey = &kGULSessionTrackerKey; [[[self class] sessionIDToFetcherMap] removeObjectForKey:sessionID]; } [[self sessionIDToFetcherMapReadWriteLock] unlock]; - - // Retain the old tracker until the lock is released. If it deallocates inside the lock, - // its -dealloc method will attempt to re-acquire the lock, resulting in a deadlock. - (void)oldTrackerToReleaseOutsideLock; } + (nullable GULNetworkURLSession *)sessionFromFetcherMapForSessionID:(NSString *)sessionID {