Skip to content

Commit d6e1383

Browse files
jonasschnellifurszy
authored andcommitted
Fix macOS launch-at-startup memory issue
1 parent 233b156 commit d6e1383

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
@@ -636,10 +636,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
636636
#elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100
637637
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m
638638

639-
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
640-
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
639+
LSSharedFileListItemRef findStartupItemInList(CFArrayRef listSnapshot, LSSharedFileListRef list, CFURLRef findUrl)
641640
{
642-
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr);
643641
if (listSnapshot == nullptr) {
644642
return nullptr;
645643
}
@@ -664,15 +662,12 @@ LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef
664662
if (currentItemURL) {
665663
if (CFEqual(currentItemURL, findUrl)) {
666664
// found
667-
CFRelease(listSnapshot);
668665
CFRelease(currentItemURL);
669666
return item;
670667
}
671668
CFRelease(currentItemURL);
672669
}
673670
}
674-
675-
CFRelease(listSnapshot);
676671
return nullptr;
677672
}
678673

@@ -684,10 +679,12 @@ bool GetStartOnSystemStartup()
684679
}
685680

686681
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
687-
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
688-
682+
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
683+
bool res = (findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl) != nullptr);
689684
CFRelease(bitcoinAppUrl);
690-
return !!foundItem; // return boolified object
685+
CFRelease(loginItems);
686+
CFRelease(listSnapshot);
687+
return res;
691688
}
692689

693690
bool SetStartOnSystemStartup(bool fAutoStart)
@@ -698,7 +695,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
698695
}
699696

700697
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
701-
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
698+
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
699+
LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl);
702700

703701
if (fAutoStart && !foundItem) {
704702
// add pivx app to startup item list
@@ -709,6 +707,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
709707
}
710708

711709
CFRelease(bitcoinAppUrl);
710+
CFRelease(loginItems);
711+
CFRelease(listSnapshot);
712712
return true;
713713
}
714714
#pragma GCC diagnostic pop

0 commit comments

Comments
 (0)