@@ -780,47 +780,64 @@ bool SetStartOnSystemStartup(bool fAutoStart)
780
780
LSSharedFileListItemRef findStartupItemInList (LSSharedFileListRef list, CFURLRef findUrl);
781
781
LSSharedFileListItemRef findStartupItemInList (LSSharedFileListRef list, CFURLRef findUrl)
782
782
{
783
- // loop through the list of startup items and try to find the bitcoin app
784
783
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot (list, nullptr );
784
+ if (listSnapshot == nullptr ) {
785
+ return nullptr ;
786
+ }
787
+
788
+ // loop through the list of startup items and try to find the bitcoin app
785
789
for (int i = 0 ; i < CFArrayGetCount (listSnapshot); i++) {
786
790
LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex (listSnapshot, i);
787
791
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes ;
788
792
CFURLRef currentItemURL = nullptr ;
789
793
790
794
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100
791
- if (&LSSharedFileListItemCopyResolvedURL)
792
- currentItemURL = LSSharedFileListItemCopyResolvedURL (item, resolutionFlags, nullptr );
795
+ if (&LSSharedFileListItemCopyResolvedURL)
796
+ currentItemURL = LSSharedFileListItemCopyResolvedURL (item, resolutionFlags, nullptr );
793
797
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100
794
- else
795
- LSSharedFileListItemResolve (item, resolutionFlags, ¤tItemURL, nullptr );
798
+ else
799
+ LSSharedFileListItemResolve (item, resolutionFlags, ¤tItemURL, nullptr );
796
800
#endif
797
801
#else
798
- LSSharedFileListItemResolve (item, resolutionFlags, ¤tItemURL, nullptr );
802
+ LSSharedFileListItemResolve (item, resolutionFlags, ¤tItemURL, nullptr );
799
803
#endif
800
804
801
- if (currentItemURL && CFEqual (currentItemURL, findUrl)) {
802
- // found
803
- CFRelease (currentItemURL);
804
- return item;
805
- }
806
805
if (currentItemURL) {
806
+ if (CFEqual (currentItemURL, findUrl)) {
807
+ // found
808
+ CFRelease (listSnapshot);
809
+ CFRelease (currentItemURL);
810
+ return item;
811
+ }
807
812
CFRelease (currentItemURL);
808
813
}
809
814
}
815
+
816
+ CFRelease (listSnapshot);
810
817
return nullptr ;
811
818
}
812
819
813
820
bool GetStartOnSystemStartup ()
814
821
{
815
822
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL (CFBundleGetMainBundle ());
823
+ if (bitcoinAppUrl == nullptr ) {
824
+ return false ;
825
+ }
826
+
816
827
LSSharedFileListRef loginItems = LSSharedFileListCreate (nullptr , kLSSharedFileListSessionLoginItems , nullptr );
817
828
LSSharedFileListItemRef foundItem = findStartupItemInList (loginItems, bitcoinAppUrl);
829
+
830
+ CFRelease (bitcoinAppUrl);
818
831
return !!foundItem; // return boolified object
819
832
}
820
833
821
834
bool SetStartOnSystemStartup (bool fAutoStart )
822
835
{
823
836
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL (CFBundleGetMainBundle ());
837
+ if (bitcoinAppUrl == nullptr ) {
838
+ return false ;
839
+ }
840
+
824
841
LSSharedFileListRef loginItems = LSSharedFileListCreate (nullptr , kLSSharedFileListSessionLoginItems , nullptr );
825
842
LSSharedFileListItemRef foundItem = findStartupItemInList (loginItems, bitcoinAppUrl);
826
843
@@ -832,6 +849,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
832
849
// remove item
833
850
LSSharedFileListItemRemove (loginItems, foundItem);
834
851
}
852
+
853
+ CFRelease (bitcoinAppUrl);
835
854
return true ;
836
855
}
837
856
#pragma GCC diagnostic pop
0 commit comments