Skip to content

Commit 94167e2

Browse files
committed
Merge #15208: Qt: remove macOS launch-at-startup when compiled with > macOS 10.11, fix memory missmanagement
da60118 Fix macOS launch-at-startup memory issue (Jonas Schnelli) 516437a Qt: remove macOS launch-at-startup option when compiled with > macOS 10.11 (Jonas Schnelli) Pull request description: The launch-at-startup API Bitcoin Core uses on macOS where removed in macOS 10.11 leading to a segmentation-fault due to the weak-linking when not actively compiled against SDK 10.11 (`-mmacosx-version-min=10.11`) This PR removes the launch-at-startup feature on macOS when compiled with macOS min version > 10.11 (the default is always the macOS version you compile on). **The depends built binaries (Gitian) are not affected since we are building with min macOS 10.10.** Users self compiling on macOS > 10.11 can re-enable the feature by compiling with min version <= 10.11 (`CXXFLAGS="-mmacosx-version-min=10.11" CFLAGS="-mmacosx-version-min=10.11" ./configure`) **Isn't there a new API from Apple?** Yes, [there is](https://developer.apple.com/library/archive/documentation/MacOSX/Conceptual/BPSystemStartup/Chapters/CreatingLoginItems.html). It will require to create a helper application which needs to be embedded in the .app folder (needs code signing as well). Developers willing to go down that rabbit hole are welcome. Fixes #15142 Tree-SHA512: fa9cc4e39d5a2d2559919b7e22b7766f5e0269a361719294d4a4a2df2fd9d955e5b23b5907e68023fdeee297f652f844f3c447904bf18f9c1145348ad101c432
2 parents 9bad1e0 + da60118 commit 94167e2

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

doc/release-notes.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,12 @@ Graphical User Interface (GUI)
262262
balance shown if the wallet was created using the `createwallet` RPC
263263
and the `disable_private_keys` parameter was set to true.
264264

265+
- The launch-on-startup option is no longer available on macOS if
266+
compiled with macosx min version greater than 10.11 (use
267+
CXXFLAGS="-mmacosx-version-min=10.11"
268+
CFLAGS="-mmacosx-version-min=10.11" for setting the deployment
269+
sdk version)
270+
265271
Low-level changes
266272
=================
267273

src/qt/guiutil.cpp

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -683,13 +683,11 @@ bool SetStartOnSystemStartup(bool fAutoStart)
683683
}
684684

685685

686-
#elif defined(Q_OS_MAC)
686+
#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

src/qt/optionsdialog.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ OptionsDialog::OptionsDialog(QWidget *parent, bool enableWallet) :
7474
#ifdef Q_OS_MAC
7575
/* remove Window tab on Mac */
7676
ui->tabWidget->removeTab(ui->tabWidget->indexOf(ui->tabWindow));
77+
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED > 101100
78+
/* hide launch at startup option if compiled against macOS > 10.11 (removed API) */
79+
ui->bitcoinAtStartup->setVisible(false);
80+
ui->verticalLayout_Main->removeWidget(ui->bitcoinAtStartup);
81+
ui->verticalLayout_Main->removeItem(ui->horizontalSpacer_0_Main);
82+
#endif
7783
#endif
7884

7985
/* remove Wallet tab in case of -disablewallet */

0 commit comments

Comments
 (0)