mirror of
https://github.com/dashpay/dash.git
synced 2024-12-27 21:12:48 +01:00
Merge #11156: Fix memory leaks in qt/guiutil.cpp
9b348ff9e
Fix memory leaks in qt/guiutil.cpp (Dan Raviv)
Pull request description:
on macOS:
`listSnapshot` was leaking in `findStartupItemInList()`
`bitcoinAppUrl` was leaking in `[Get|Set]StartOnSystemStartup()`
Tree-SHA512: dd49e1166336cf4f20035d21930f2f99f21f1d9f91a1101b1434a23dd0b92d402ac7efb177473c758d8af1dbab8d8750485583231c5b5854203d2493f0b43e73
This commit is contained in:
commit
a3624ddb1a
@ -781,47 +781,64 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
|||||||
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
|
LSSharedFileListItemRef findStartupItemInList(LSSharedFileListRef list, CFURLRef findUrl);
|
||||||
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);
|
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++) {
|
for(int i = 0; i < CFArrayGetCount(listSnapshot); i++) {
|
||||||
LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i);
|
LSSharedFileListItemRef item = (LSSharedFileListItemRef)CFArrayGetValueAtIndex(listSnapshot, i);
|
||||||
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
|
UInt32 resolutionFlags = kLSSharedFileListNoUserInteraction | kLSSharedFileListDoNotMountVolumes;
|
||||||
CFURLRef currentItemURL = nullptr;
|
CFURLRef currentItemURL = nullptr;
|
||||||
|
|
||||||
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100
|
#if defined(MAC_OS_X_VERSION_MAX_ALLOWED) && MAC_OS_X_VERSION_MAX_ALLOWED >= 10100
|
||||||
if(&LSSharedFileListItemCopyResolvedURL)
|
if(&LSSharedFileListItemCopyResolvedURL)
|
||||||
currentItemURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nullptr);
|
currentItemURL = LSSharedFileListItemCopyResolvedURL(item, resolutionFlags, nullptr);
|
||||||
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100
|
#if defined(MAC_OS_X_VERSION_MIN_REQUIRED) && MAC_OS_X_VERSION_MIN_REQUIRED < 10100
|
||||||
else
|
else
|
||||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr);
|
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr);
|
||||||
#endif
|
#endif
|
||||||
#else
|
#else
|
||||||
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr);
|
LSSharedFileListItemResolve(item, resolutionFlags, ¤tItemURL, nullptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(currentItemURL && CFEqual(currentItemURL, findUrl)) {
|
|
||||||
// found
|
|
||||||
CFRelease(currentItemURL);
|
|
||||||
return item;
|
|
||||||
}
|
|
||||||
if(currentItemURL) {
|
if(currentItemURL) {
|
||||||
|
if (CFEqual(currentItemURL, findUrl)) {
|
||||||
|
// found
|
||||||
|
CFRelease(listSnapshot);
|
||||||
|
CFRelease(currentItemURL);
|
||||||
|
return item;
|
||||||
|
}
|
||||||
CFRelease(currentItemURL);
|
CFRelease(currentItemURL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CFRelease(listSnapshot);
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool GetStartOnSystemStartup()
|
bool GetStartOnSystemStartup()
|
||||||
{
|
{
|
||||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||||
|
if (bitcoinAppUrl == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
||||||
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
||||||
|
|
||||||
|
CFRelease(bitcoinAppUrl);
|
||||||
return !!foundItem; // return boolified object
|
return !!foundItem; // return boolified object
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SetStartOnSystemStartup(bool fAutoStart)
|
bool SetStartOnSystemStartup(bool fAutoStart)
|
||||||
{
|
{
|
||||||
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
CFURLRef bitcoinAppUrl = CFBundleCopyBundleURL(CFBundleGetMainBundle());
|
||||||
|
if (bitcoinAppUrl == nullptr) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
LSSharedFileListRef loginItems = LSSharedFileListCreate(nullptr, kLSSharedFileListSessionLoginItems, nullptr);
|
||||||
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
LSSharedFileListItemRef foundItem = findStartupItemInList(loginItems, bitcoinAppUrl);
|
||||||
|
|
||||||
@ -833,6 +850,8 @@ bool SetStartOnSystemStartup(bool fAutoStart)
|
|||||||
// remove item
|
// remove item
|
||||||
LSSharedFileListItemRemove(loginItems, foundItem);
|
LSSharedFileListItemRemove(loginItems, foundItem);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
CFRelease(bitcoinAppUrl);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
Loading…
Reference in New Issue
Block a user