Skip to content

Commit

Permalink
Fix bug: Attempt to insert into immutable dictionary.
Browse files Browse the repository at this point in the history
For some reason this bug only manifests itself in release mode, on Xcode 12.
Fixes Github issue 817
  • Loading branch information
kstenerud committed Sep 24, 2020
1 parent fcc42bb commit de4a5c7
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions Bugsnag/BSGOutOfMemoryWatchdog.m
Original file line number Diff line number Diff line change
Expand Up @@ -274,17 +274,19 @@ - (NSDictionary *)readSentinelFile {
bsg_log_err(@"Failed to read oom watchdog file: %@", error);
return nil;
}
NSDictionary *contents = [BSGJSONSerialization JSONObjectWithData:data options:0 error:&error];
NSMutableDictionary *contents = [[BSGJSONSerialization JSONObjectWithData:data options:0 error:&error] mutableCopy];
if (error) {
bsg_log_err(@"Failed to read oom watchdog file: %@", error);
return nil;
}

NSMutableDictionary *app = [contents[BSGKeyApp] mutableCopy];
// Override JSON data with KV store data
contents[BSGKeyApp][APP_KEY_IS_MONITORING_OOM] = [self.kvStore NSBooleanForKey:KV_KEY_IS_MONITORING_OOM defaultValue:false];
contents[BSGKeyApp][APP_KEY_IS_ACTIVE] = [self.kvStore NSBooleanForKey:KV_KEY_IS_ACTIVE defaultValue:false];
contents[BSGKeyApp][APP_KEY_IS_IN_FOREGROUND] = [self.kvStore NSBooleanForKey:KV_KEY_IS_IN_FOREGROUND defaultValue:false];
contents[BSGKeyDevice][DEVICE_KEY_LAST_LOW_MEMORY_WARNING] = [self.kvStore stringForKey:KV_KEY_LAST_LOW_MEMORY_WARNING defaultValue:@""];
app[APP_KEY_IS_MONITORING_OOM] = [self.kvStore NSBooleanForKey:KV_KEY_IS_MONITORING_OOM defaultValue:false];
app[APP_KEY_IS_ACTIVE] = [self.kvStore NSBooleanForKey:KV_KEY_IS_ACTIVE defaultValue:false];
app[APP_KEY_IS_IN_FOREGROUND] = [self.kvStore NSBooleanForKey:KV_KEY_IS_IN_FOREGROUND defaultValue:false];
app[DEVICE_KEY_LAST_LOW_MEMORY_WARNING] = [self.kvStore stringForKey:KV_KEY_LAST_LOW_MEMORY_WARNING defaultValue:@""];
contents[BSGKeyApp] = app;

return contents;
}
Expand Down

0 comments on commit de4a5c7

Please sign in to comment.