aboutsummaryrefslogtreecommitdiff
path: root/src/qt/guiutil.cpp
diff options
context:
space:
mode:
authorDan Raviv <dan@soundradix.com>2017-08-26 13:23:19 +0300
committerDan Raviv <dan@soundradix.com>2017-08-26 13:24:25 +0300
commit9b348ff9eb75e04249dfa873a34e0d1a31993b9c (patch)
treebfeab5ed415ea1deb98c8885cf4faac5eba043c6 /src/qt/guiutil.cpp
parent07c92b98e2a0a29d19b5ccdbbfa9addc1e80b306 (diff)
downloadbitcoin-9b348ff9eb75e04249dfa873a34e0d1a31993b9c.tar.xz
Fix memory leaks in qt/guiutil.cpp
on macOS: listSnapshot was leaking in findStartupItemInList() bitcoinAppUrl was leaking in [Get|Set]StartOnSystemStartup()
Diffstat (limited to 'src/qt/guiutil.cpp')
-rw-r--r--src/qt/guiutil.cpp41
1 files changed, 30 insertions, 11 deletions
diff --git a/src/qt/guiutil.cpp b/src/qt/guiutil.cpp
index f3c5daebec..2557344c1f 100644
--- a/src/qt/guiutil.cpp
+++ b/src/qt/guiutil.cpp
@@ -780,47 +780,64 @@ bool SetStartOnSystemStartup(bool fAutoStart)
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl)
{
- // loop through the list of startup items and try to find the bitcoin app
CFArrayRef listSnapshot = LSSharedFileListCopySnapshot(list, nullptr);
+ if (listSnapshot == nullptr) {
+ return nullptr;
+ }
+
+ // loop through the list of startup items and try to find the bitcoin app
for(int i = 0; i < CFArrayGetCount(listSnapshot); i++) {
LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i);
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
CFURLRef currentItemURL = nullptr;
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100
- if(&LSSharedFileListItemCopyResolvedURL)
- currentItemURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nullptr);
+ if(&LSSharedFileListItemCopyResolvedURL)
+ currentItemURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nullptr);
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100
- else
- LSSharedFileListItemResolve(item, resolutionFlags, &currentItemURL, nullptr);
+ else
+ LSSharedFileListItemResolve(item, resolutionFlags, &currentItemURL, nullptr);
#endif
#else
- LSSharedFileListItemResolve(item, resolutionFlags, &currentItemURL, nullptr);
+ LSSharedFileListItemResolve(item, resolutionFlags, &currentItemURL, nullptr);
#endif
- if(currentItemURL && CFEqual(currentItemURL, findUrl)) {
- // found
- CFRelease(currentItemURL);
- return item;
- }
if(currentItemURL) {
+ if (CFEqual(currentItemURL, findUrl)) {
+ // found
+ CFRelease(listSnapshot);
+ CFRelease(currentItemURL);
+ return item;
+ }
CFRelease(currentItemURL);
}
}
+
+ CFRelease(listSnapshot);
return nullptr;
}
bool GetStartOnSystemStartup()
{
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+ if (bitcoinAppUrl == nullptr) {
+ return false;
+ }
+
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
+
+ CFRelease(bitcoinAppUrl);
return !!foundItem; // return boolified object
}
bool SetStartOnSystemStartup(bool fAutoStart)
{
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
+ if (bitcoinAppUrl == nullptr) {
+ return false;
+ }
+
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
@@ -832,6 +849,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
// remove item
LSSharedFileListItemRemove(loginItems, foundItem);
}
+
+ CFRelease(bitcoinAppUrl);
return true;
}
#pragma GCC diagnostic pop