Skip to content

Commit 7147ecc

Browse files
authored
Fix FirebaseSessions release mode crash (#12425)
1 parent e463466 commit 7147ecc

File tree

5 files changed

+28
-13
lines changed

5 files changed

+28
-13
lines changed

Crashlytics/CHANGELOG.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
# Unreleased
1+
# 10.22.0
22
- [changed] Removed calls to statfs in the Crashlytics SDK to comply with Apple Privacy Manifests. This change removes support for collecting Disk Space Free in Crashlytics reports.
3+
- [fixed] Fixed FirebaseSessions crash on startup that occurs in release mode in Xcode 15.3 and other build configurations. (#11403)
34

45
# 10.16.0
56
- [fixed] Fixed a memory leak regression when generating session events (#11725).

FirebaseSessions/Sources/SessionStartEvent.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -150,18 +150,7 @@ class SessionStartEvent: NSObject, GDTCOREventDataObject {
150150
// MARK: - GDTCOREventDataObject
151151

152152
func transportBytes() -> Data {
153-
var fields = firebase_appquality_sessions_SessionEvent_fields
154-
var error: NSError?
155-
let data = FIRSESEncodeProto(&fields.0, &proto, &error)
156-
if error != nil {
157-
Logger
158-
.logError("Session Event failed to encode as proto with error: \(error.debugDescription)")
159-
}
160-
guard let data = data else {
161-
Logger.logError("Session Event generated nil transportBytes. Returning empty data.")
162-
return Data()
163-
}
164-
return data
153+
return FIRSESTransportBytes(&proto)
165154
}
166155

167156
// MARK: - Data Conversion

FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ pb_size_t FIRSESGetAppleApplicationInfoTag(void);
9191
/// private method in GULAppEnvironmentUtil.
9292
NSString* _Nullable FIRSESGetSysctlEntry(const char* sysctlKey);
9393

94+
/// C function to bridge from Swift to do nanopb bytes transfer.
95+
NSData* FIRSESTransportBytes(const void* _Nonnull proto);
96+
9497
NS_ASSUME_NONNULL_END
9598

9699
#endif /* FIRSESNanoPBHelpers_h */

FirebaseSessions/SourcesObjC/NanoPB/FIRSESNanoPBHelpers.m

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121

2222
#import "FirebaseSessions/SourcesObjC/Protogen/nanopb/sessions.nanopb.h"
2323

24+
@import FirebaseCoreExtension;
25+
2426
#import <nanopb/pb.h>
2527
#import <nanopb/pb_decode.h>
2628
#import <nanopb/pb_encode.h>
@@ -182,4 +184,22 @@ pb_size_t FIRSESGetAppleApplicationInfoTag(void) {
182184
}
183185
}
184186

187+
NSData *FIRSESTransportBytes(const void *_Nonnull proto) {
188+
const pb_field_t *fields = firebase_appquality_sessions_SessionEvent_fields;
189+
NSError *error;
190+
NSData *data = FIRSESEncodeProto(fields, proto, &error);
191+
if (error != nil) {
192+
FIRLogError(
193+
@"FirebaseSessions", @"I-SES000001", @"%@",
194+
[NSString stringWithFormat:@"Session Event failed to encode as proto with error: %@",
195+
error.debugDescription]);
196+
}
197+
if (data == nil) {
198+
data = [NSData data];
199+
FIRLogError(@"FirebaseSessions", @"I-SES000002",
200+
@"Session Event generated nil transportBytes. Returning empty data.");
201+
}
202+
return data;
203+
}
204+
185205
NS_ASSUME_NONNULL_END

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1076,6 +1076,8 @@ let package = Package(
10761076
.target(
10771077
name: "FirebaseSessionsObjC",
10781078
dependencies: [
1079+
"FirebaseCore",
1080+
"FirebaseCoreExtension",
10791081
.product(name: "GULEnvironment", package: "GoogleUtilities"),
10801082
.product(name: "nanopb", package: "nanopb"),
10811083
],

0 commit comments

Comments
 (0)