From 6c7a3e581c6bc21441d194f7fa8b8878cad6750e Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 14 Jun 2022 21:27:51 -0700 Subject: [PATCH] [Playlist/Metadata] Prevent a race condition Prevent a race condition with deleting playlist entries while their metadata is still being loaded by the player. Signed-off-by: Christopher Snowhill --- Playlist/PlaylistLoader.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 2a0d65e3f..aae3e940a 100644 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -559,6 +559,8 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc progress += progressstep; [weakLock unlock]; + if(weakPe.deleted) return; + DLog(@"Loading metadata for %@", weakPe.URL); NSDictionary *entryProperties = [AudioPropertiesReader propertiesForURL:weakPe.URL]; @@ -590,8 +592,10 @@ static inline void dispatch_sync_reentrant(dispatch_queue_t queue, dispatch_bloc __block PlaylistEntry *weakPe = [outArray objectAtIndex:i]; __block NSDictionary *entryInfo = [outArray objectAtIndex:i + 1]; dispatch_sync_reentrant(dispatch_get_main_queue(), ^{ - [weakPe setMetadata:entryInfo]; - [store trackUpdate:weakPe]; + if(!weakPe.deleted) { + [weakPe setMetadata:entryInfo]; + [store trackUpdate:weakPe]; + } progress += progressstep; [self setProgressBarStatus:progress]; });