From aa743941e84a4f83e47cc51ed0893ba3f4cc9dd6 Mon Sep 17 00:00:00 2001 From: rumtid Date: Tue, 19 Mar 2024 18:09:09 +0800 Subject: [PATCH] Fix a few errors that cause crashes --- src/utils/utils-mac.mm | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/utils/utils-mac.mm b/src/utils/utils-mac.mm index 1e2456708..ed30177b9 100644 --- a/src/utils/utils-mac.mm +++ b/src/utils/utils-mac.mm @@ -167,21 +167,24 @@ bool get_auto_start() #if (__MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) outURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, /*outError*/ NULL); if (outURL == NULL) { + continue; + } #else OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &outURL, /*outRef*/ NULL); if (err != noErr || outURL == NULL) { -#endif if (outURL) CFRelease(outURL); continue; } +#endif found = CFEqual(outURL, URLToToggle); CFRelease(outURL); if (found) break; } - CFRelease(currentLoginItems); + if (currentLoginItems) + CFRelease(currentLoginItems); CFRelease(loginItems); } return found; @@ -209,14 +212,16 @@ void set_auto_start(bool enabled) #if (__MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_10) outURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, /*outError*/ NULL); if (outURL == NULL) { + continue; + } #else OSStatus err = LSSharedFileListItemResolve(item, resolutionFlags, &outURL, /*outRef*/ NULL); if (err != noErr || outURL == NULL) { -#endif if (outURL) CFRelease(outURL); continue; } +#endif found = CFEqual(outURL, URLToToggle); CFRelease(outURL); @@ -258,7 +263,8 @@ void set_auto_start(bool enabled) LSSharedFileListItemRemove(loginItems, existingItem); } - CFRelease(currentLoginItems); + if (currentLoginItems) + CFRelease(currentLoginItems); CFRelease(loginItems); } }