From 3b84187cd14b55f1456ebd9b195c7aeeb4ec7ef4 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 15 Nov 2021 17:15:44 +0100 Subject: [PATCH] Fix leak in date and time formatting on macOS MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CFDateFormatterCreateStringWithDate() creates a CFStringRef that we need to tidy up once we're done with it, so use the QCFType template to take care of that. Change-Id: Ibc3751426cc4496bce25307918fdb11722cde3b2 Reviewed-by: Tor Arne Vestbø Reviewed-by: Timur Pocheptsov --- src/corelib/text/qlocale_mac.mm | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/corelib/text/qlocale_mac.mm b/src/corelib/text/qlocale_mac.mm index 4293cdda27..ce693fb224 100644 --- a/src/corelib/text/qlocale_mac.mm +++ b/src/corelib/text/qlocale_mac.mm @@ -157,7 +157,8 @@ static QVariant macDateToString(QDate date, bool short_format) = CFDateFormatterCreate(kCFAllocatorDefault, mylocale, style, kCFDateFormatterNoStyle); - return QString::fromCFString(CFDateFormatterCreateStringWithDate(0, myFormatter, myDate)); + QCFType text = CFDateFormatterCreateStringWithDate(0, myFormatter, myDate); + return QString::fromCFString(text); } static QVariant macTimeToString(QTime time, bool short_format) @@ -169,7 +170,8 @@ static QVariant macTimeToString(QTime time, bool short_format) mylocale, kCFDateFormatterNoStyle, style); - return QString::fromCFString(CFDateFormatterCreateStringWithDate(0, myFormatter, myDate)); + QCFType text = CFDateFormatterCreateStringWithDate(0, myFormatter, myDate); + return QString::fromCFString(text); } // Mac uses the Unicode CLDR format codes