Skip to content

Commit

Permalink
Merge pull request #308 from bugsnag/session-memory-fix
Browse files Browse the repository at this point in the history
Prevent potential crash during app teardown
  • Loading branch information
fractalwrench authored Sep 3, 2018
2 parents 3a68f27 + d287de4 commit 2fb5e43
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 4 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
Changelog
=========

## 5.X.X (TBD)

### Bug Fixes

* Prevent potential crash in session delivery during app teardown [#308](https://github.com/bugsnag/bugsnag-cocoa/pull/308)

## 5.16.3 (14 Aug 2018)

### Bug Fixes
Expand Down
4 changes: 4 additions & 0 deletions Source/BugsnagApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,10 @@ - (NSMutableURLRequest *)prepareRequest:(NSURL *)url
return request;
}

- (void)dealloc {
[self.sendQueue cancelAllOperations];
}

@end

@implementation BSGDelayOperation
Expand Down
11 changes: 7 additions & 4 deletions Source/BugsnagSessionTrackingApiClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ - (NSOperation *)deliveryOperation {
}

- (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
NSString *apiKey = [self.config.apiKey copy];
NSURL *sessionURL = [self.config.sessionURL copy];

[self.sendQueue addOperationWithBlock:^{
if (!self.config.apiKey) {
if (!apiKey) {
bsg_log_err(@"No API key set. Refusing to send sessions.");
return;
}
Expand All @@ -41,16 +44,16 @@ - (void)deliverSessionsInStore:(BugsnagSessionFileStore *)store {
if (sessionCount > 0) {
NSDictionary *HTTPHeaders = @{
@"Bugsnag-Payload-Version": @"1.0",
@"Bugsnag-API-Key": self.config.apiKey,
@"Bugsnag-API-Key": apiKey,
@"Bugsnag-Sent-At": [BSG_RFC3339DateTool stringFromDate:[NSDate new]]
};
[self sendData:payload
withPayload:[payload toJson]
toURL:self.config.sessionURL
toURL:sessionURL
headers:HTTPHeaders
onCompletion:^(id data, BOOL success, NSError *error) {
if (success && error == nil) {
bsg_log_info(@"Sent %lu sessions to Bugsnag", (unsigned long)sessionCount);
bsg_log_info(@"Sent %lu sessions to Bugsnag", (unsigned long) sessionCount);

for (NSString *fileId in fileIds) {
[store deleteFileWithId:fileId];
Expand Down

0 comments on commit 2fb5e43

Please sign in to comment.