From 746d8fb70b9bce9f896304f2f070118e2d90ad97 Mon Sep 17 00:00:00 2001 From: Jesus Rojas Date: Wed, 10 Sep 2025 16:55:39 -0600 Subject: [PATCH 1/2] Safely copy MIMEType to prevent use after fre Copied response.MIMEType before assigning to responseContentType to avoid EXC_BAD_ACCESS caused by early deallocation under certain network or SDK conditions. --- .../Sources/Instrumentation/FPRNetworkTrace.m | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m b/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m index 380e57dae0e..2aa3af8fe54 100644 --- a/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m +++ b/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m @@ -251,7 +251,10 @@ - (void)didCompleteRequestWithResponse:(NSURLResponse *)response error:(NSError self.responseCode = (int32_t)HTTPResponse.statusCode; } self.responseError = error; - self.responseContentType = response.MIMEType; + //Safely copy MIMEType to prevent use after free + NSURLResponse *strongRes = response; + NSString *mime = [[strongRes MIMEType] copy]; + self.responseContentType = (mime.length ? mime : nil); [self checkpointState:FPRNetworkTraceCheckpointStateResponseCompleted]; // Send the network trace for logging. From 40e19d5a0fccecbae97e5f00eb68aeb405ca034c Mon Sep 17 00:00:00 2001 From: Jesus Rojas Date: Wed, 10 Sep 2025 17:40:34 -0600 Subject: [PATCH 2/2] Fix Styling and applied review suggestions --- .../Sources/Instrumentation/FPRNetworkTrace.m | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m b/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m index 2aa3af8fe54..9bb4a1c46f2 100644 --- a/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m +++ b/FirebasePerformance/Sources/Instrumentation/FPRNetworkTrace.m @@ -251,9 +251,8 @@ - (void)didCompleteRequestWithResponse:(NSURLResponse *)response error:(NSError self.responseCode = (int32_t)HTTPResponse.statusCode; } self.responseError = error; - //Safely copy MIMEType to prevent use after free - NSURLResponse *strongRes = response; - NSString *mime = [[strongRes MIMEType] copy]; + // Safely copy MIMEType to prevent use after free + NSString *mime = [response.MIMEType copy]; self.responseContentType = (mime.length ? mime : nil); [self checkpointState:FPRNetworkTraceCheckpointStateResponseCompleted];