Skip to content

Commit

Permalink
Avoid memory leak on macOS
Browse files Browse the repository at this point in the history
Only Mark-of-the-Web and Power Management are affected.

PR qbittorrent#22176.
  • Loading branch information
Chocobo1 committed Jan 18, 2025
1 parent 35dce07 commit d9a57b4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/base/utils/os.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,11 @@ bool Utils::OS::applyMarkOfTheWeb(const Path &file, const QString &url)

::CFDictionarySetValue(properties, kLSQuarantineTypeKey, kLSQuarantineTypeOtherDownload);
if (!url.isEmpty())
::CFDictionarySetValue(properties, kLSQuarantineDataURLKey, url.toCFString());
{
const CFStringRef urlCFString = url.toCFString();
[[maybe_unused]] const auto urlStringGuard = qScopeGuard([&urlCFString] { ::CFRelease(urlCFString); });
::CFDictionarySetValue(properties, kLSQuarantineDataURLKey, urlCFString);
}

const Boolean success = ::CFURLSetResourcePropertyForKey(fileURL, kCFURLQuarantinePropertiesKey
, properties, NULL);
Expand Down
5 changes: 4 additions & 1 deletion src/gui/powermanagement/powermanagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@

#ifdef Q_OS_MACOS
#include <IOKit/pwr_mgt/IOPMLib.h>
#include <QScopeGuard>
#endif

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -74,8 +75,10 @@ void PowerManagement::setBusy()
#elif defined(QBT_USES_DBUS)
m_inhibitor->requestBusy();
#elif defined(Q_OS_MACOS)
const CFStringRef assertName = tr("qBittorrent is active").toCFString();
[[maybe_unused]] const auto assertNameGuard = qScopeGuard([&assertName] { ::CFRelease(assertName); });
const IOReturn success = ::IOPMAssertionCreateWithName(kIOPMAssertionTypeNoIdleSleep, kIOPMAssertionLevelOn
, tr("qBittorrent is active").toCFString(), &m_assertionID);
, assertName, &m_assertionID);
if (success != kIOReturnSuccess)
m_busy = false;
#endif
Expand Down

0 comments on commit d9a57b4

Please sign in to comment.