From 65293dab30ba6bdb52db95acddffcd59545288b6 Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 6 Dec 2020 00:56:16 -0600 Subject: [PATCH] Fix race condition during PC detection --- Limelight/ViewControllers/MainFrameViewController.m | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/Limelight/ViewControllers/MainFrameViewController.m b/Limelight/ViewControllers/MainFrameViewController.m index 8114f9e..4f96216 100644 --- a/Limelight/ViewControllers/MainFrameViewController.m +++ b/Limelight/ViewControllers/MainFrameViewController.m @@ -1145,14 +1145,17 @@ static NSMutableSet* hostList; } - (void) updateAllHosts:(NSArray *)hosts { + // We must copy the array here because it could be modified + // before our main thread dispatch happens. + NSArray* hostsCopy = [NSArray arrayWithArray:hosts]; dispatch_async(dispatch_get_main_queue(), ^{ Log(LOG_D, @"New host list:"); - for (TemporaryHost* host in hosts) { + for (TemporaryHost* host in hostsCopy) { Log(LOG_D, @"Host: \n{\n\t name:%@ \n\t address:%@ \n\t localAddress:%@ \n\t externalAddress:%@ \n\t ipv6Address:%@ \n\t uuid:%@ \n\t mac:%@ \n\t pairState:%d \n\t online:%d \n\t activeAddress:%@ \n}", host.name, host.address, host.localAddress, host.externalAddress, host.ipv6Address, host.uuid, host.mac, host.pairState, host.state, host.activeAddress); } @synchronized(hostList) { [hostList removeAllObjects]; - [hostList addObjectsFromArray:hosts]; + [hostList addObjectsFromArray:hostsCopy]; } [self updateHosts]; });