Skip to content

Commit da60118

Browse files
committed
Fix macOS launch-at-startup memory issue
1 parent 516437a commit da60118

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/qt/guiutil.cpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -686,10 +686,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
686686
#elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100
687687
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
688688

689-
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
690-
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
689+
LSSharedFileListItemRef findStartupItemInList(CFArrayRef listSnapshot, LSSharedFileListRef list, CFURLRef findUrl)
691690
{
692-
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr);
693691
if (listSnapshot == nullptr) {
694692
return nullptr;
695693
}
@@ -714,15 +712,12 @@ LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef
714712
if(currentItemURL) {
715713
if (CFEqual(currentItemURL, findUrl)) {
716714
// found
717-
CFRelease(listSnapshot);
718715
CFRelease(currentItemURL);
719716
return item;
720717
}
721718
CFRelease(currentItemURL);
722719
}
723720
}
724-
725-
CFRelease(listSnapshot);
726721
return nullptr;
727722
}
728723

@@ -734,10 +729,12 @@ bool GetStartOnSystemStartup()
734729
}
735730

736731
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
737-
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
738-
732+
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
733+
bool res = (findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl) != nullptr);
739734
CFRelease(bitcoinAppUrl);
740-
return !!foundItem; // return boolified object
735+
CFRelease(loginItems);
736+
CFRelease(listSnapshot);
737+
return res;
741738
}
742739

743740
bool SetStartOnSystemStartup(bool fAutoStart)
@@ -748,7 +745,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
748745
}
749746

750747
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
751-
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
748+
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
749+
LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl);
752750

753751
if(fAutoStart && !foundItem) {
754752
// add bitcoin app to startup item list
@@ -760,6 +758,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
760758
}
761759

762760
CFRelease(bitcoinAppUrl);
761+
CFRelease(loginItems);
762+
CFRelease(listSnapshot);
763763
return true;
764764
}
765765
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)