diff options
author | Patrick Luby <guibmacdev@gmail.com> | 2024-06-27 20:05:19 -0400 |
---|---|---|
committer | Patrick Luby <guibomacdev@gmail.com> | 2024-06-28 13:23:36 +0200 |
commit | 2e87c644245751aea9f50faf16c4ca4d57b0c2f1 (patch) | |
tree | 75b58aa165f2f4cc0a4fd9f0a36a219391dac18a | |
parent | 2fd72ed9cb8bb1fd7c5402194ac36e43fc2c0963 (diff) |
tdf#159680 fix memory leak of CTFontRef
The CTFontRef in CoreTextFontFace::GetVariations() was never
released and a new CTFontRef was allocated in every call to
CoreTextFontFace::GetVariations(). So release the CTFontRef
and only allocate it once when mxVariations is populated.
Change-Id: I08999956501d5860fff67e48001ef85a62ca8079
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/169690
Tested-by: Jenkins
Reviewed-by: Patrick Luby <guibomacdev@gmail.com>
-rw-r--r-- | vcl/quartz/CoreTextFontFace.cxx | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/vcl/quartz/CoreTextFontFace.cxx b/vcl/quartz/CoreTextFontFace.cxx index 662b439a9eae..47792fff7a58 100644 --- a/vcl/quartz/CoreTextFontFace.cxx +++ b/vcl/quartz/CoreTextFontFace.cxx @@ -46,43 +46,46 @@ sal_IntPtr CoreTextFontFace::GetFontId() const const std::vector<hb_variation_t>& CoreTextFontFace::GetVariations(const LogicalFontInstance&) const { - CTFontRef pFont = CTFontCreateWithFontDescriptor(mxFontDescriptor, 0.0, nullptr); - if (!mxVariations) { mxVariations.emplace(); - CFArrayRef pAxes = CTFontCopyVariationAxes(pFont); - if (pAxes) + CTFontRef pFont = CTFontCreateWithFontDescriptor(mxFontDescriptor, 0.0, nullptr); + if (pFont) { - CFDictionaryRef pVariations = CTFontCopyVariation(pFont); - if (pVariations) + CFArrayRef pAxes = CTFontCopyVariationAxes(pFont); + if (pAxes) { - CFIndex nAxes = CFArrayGetCount(pAxes); - for (CFIndex i = 0; i < nAxes; ++i) + CFDictionaryRef pVariations = CTFontCopyVariation(pFont); + if (pVariations) { - auto pAxis = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(pAxes, i)); - if (pAxis) + CFIndex nAxes = CFArrayGetCount(pAxes); + for (CFIndex i = 0; i < nAxes; ++i) { - hb_tag_t nTag; - auto pTag = static_cast<CFNumberRef>( - CFDictionaryGetValue(pAxis, kCTFontVariationAxisIdentifierKey)); - if (!pTag) - continue; - CFNumberGetValue(pTag, kCFNumberIntType, &nTag); + auto pAxis = static_cast<CFDictionaryRef>(CFArrayGetValueAtIndex(pAxes, i)); + if (pAxis) + { + hb_tag_t nTag; + auto pTag = static_cast<CFNumberRef>( + CFDictionaryGetValue(pAxis, kCTFontVariationAxisIdentifierKey)); + if (!pTag) + continue; + CFNumberGetValue(pTag, kCFNumberIntType, &nTag); - float fValue; - auto pValue - = static_cast<CFNumberRef>(CFDictionaryGetValue(pVariations, pTag)); - if (!pValue) - continue; - CFNumberGetValue(pValue, kCFNumberFloatType, &fValue); + float fValue; + auto pValue + = static_cast<CFNumberRef>(CFDictionaryGetValue(pVariations, pTag)); + if (!pValue) + continue; + CFNumberGetValue(pValue, kCFNumberFloatType, &fValue); - mxVariations->push_back({ nTag, fValue }); + mxVariations->push_back({ nTag, fValue }); + } } + CFRelease(pVariations); } - CFRelease(pVariations); + CFRelease(pAxes); } - CFRelease(pAxes); + CFRelease(pFont); } } |