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