Skip to content

Commit

Permalink
Fix macOS launch-at-startup memory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jonasschnelli committed Jan 22, 2019
1 parent 516437a commit da60118
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/qt/guiutil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -686,10 +686,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
#elif defined(Q_OS_MAC) && defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED <= 101100
// based on: https://github.com/Mozketo/LaunchAtLoginController/blob/master/LaunchAtLoginController.m

LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
LSSharedFileListItemRef findStartupItemInList(CFArrayRef listSnapshot, LSSharedFileListRef list, CFURLRef findUrl)
{
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr);
if (listSnapshot == nullptr) {
return nullptr;
}
Expand All @@ -714,15 +712,12 @@ LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef
if(currentItemURL) {
if (CFEqual(currentItemURL, findUrl)) {
// found
CFRelease(listSnapshot);
CFRelease(currentItemURL);
return item;
}
CFRelease(currentItemURL);
}
}

CFRelease(listSnapshot);
return nullptr;
}

Expand All @@ -734,10 +729,12 @@ bool GetStartOnSystemStartup()
}

LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);

CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
bool res = (findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl) != nullptr);
CFRelease(bitcoinAppUrl);
return !!foundItem; // return boolified object
CFRelease(loginItems);
CFRelease(listSnapshot);
return res;
}

bool SetStartOnSystemStartup(bool fAutoStart)
Expand All @@ -748,7 +745,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
}

LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(loginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(listSnapshot, loginItems, bitcoinAppUrl);

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

CFRelease(bitcoinAppUrl);
CFRelease(loginItems);
CFRelease(listSnapshot);
return true;
}
#pragma GCC diagnostic pop
Expand Down

0 comments on commit da60118

Please sign in to comment.