From 808b8bce8d0c99e2c16a2c2f89ae0a8129b38fa8 Mon Sep 17 00:00:00 2001 From: Tom Longridge Date: Fri, 10 Jul 2020 11:55:31 +0100 Subject: [PATCH] fix(breadcrumbs): reinstate dispatch barrier guard --- Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m | 30 +++++++++++++----------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m b/Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m index 49ed464f9..6391637f0 100644 --- a/Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m +++ b/Bugsnag/Breadcrumbs/BugsnagBreadcrumbs.m @@ -116,22 +116,24 @@ - (NSArray *)cachedBreadcrumbs { } - (NSArray *)arrayValue { - NSMutableArray *crumbs = [self.breadcrumbs mutableCopy]; - NSMutableArray *contents = [[NSMutableArray alloc] initWithCapacity:[crumbs count]]; - for (BugsnagBreadcrumb *crumb in crumbs) { - NSDictionary *objectValue = [crumb objectValue]; - NSError *error = nil; - @try { - if (![NSJSONSerialization isValidJSONObject:objectValue]) { - bsg_log_err(@"Unable to serialize breadcrumb: Not a valid " - @"JSON object"); - continue; + __block NSMutableArray *contents = + [[NSMutableArray alloc] initWithCapacity:self.breadcrumbs.count]; + dispatch_barrier_sync(self.readWriteQueue, ^{ + for (BugsnagBreadcrumb *crumb in self.breadcrumbs) { + NSDictionary *objectValue = [crumb objectValue]; + NSError *error = nil; + @try { + if (![NSJSONSerialization isValidJSONObject:objectValue]) { + bsg_log_err(@"Unable to serialize breadcrumb: Not a valid " + @"JSON object"); + continue; + } + [contents addObject:objectValue]; + } @catch (NSException *exception) { + bsg_log_err(@"Unable to serialize breadcrumb: %@", error); } - [contents addObject:objectValue]; - } @catch (NSException *exception) { - bsg_log_err(@"Unable to serialize breadcrumb: %@", error); } - } + }); return contents; }