Description: CoreTextGlyphFallbackSubstitution::FindFontSubstitute() leaks memory on invocation. Steps to Reproduce: Steps to Reproduce: 1. Start XCode, then Instruments.app 2. Choose Memory Leak profile tool 3. Select LibreOffice.app in instdir as target process 4. Click on the record button, LODev is started by the profiling tool 5. Wait for the StartCenter to load - note the occurrences of memory leaks as they occur. 6. Open a new Writer document. 7. When the document has loaded, click on the dropdown font list. Scroll up and down the list with the Up/Down cursor arrows 8. Stop recording. 9. Analyse the profile trace. Actual Results: CoreTextGlyphFallbackSubstitution::FindFontSubstitute() leaks memory on invocation. Invoked multiple times in CFData, CFDictionary, and multiple MALLOCS of 336 bytes each Expected Results: It shouldn't leak memory. Reproducible: Always User Profile Reset: No Additional Info: User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:54.0) Gecko/20100101 Firefox/54.0
Created attachment 135286 [details] Screenshot of memory leak profiling with Instruments.app
The leak appears to occur here : line 80, salgdi.xx : CTFontDescriptorRef pDesc = CTFontCopyFontDescriptor(pFallback); from this block : bool bFound = false; CoreTextStyle rStyle(rPattern); CTFontRef pFont = static_cast<CTFontRef>(CFDictionaryGetValue(rStyle.GetStyleDict(), kCTFontAttributeName)); CFStringRef pStr = CreateCFString(rMissingChars); if (pStr) { CTFontRef pFallback = CTFontCreateForString(pFont, pStr, CFRangeMake(0, CFStringGetLength(pStr))); if (pFallback) { bFound = true; CTFontDescriptorRef pDesc = CTFontCopyFontDescriptor(pFallback); FontAttributes rAttr = DevFontFromCTFontDescriptor(pDesc, nullptr); rPattern.maSearchName = rAttr.GetFamilyName(); rPattern.SetWeight(rAttr.GetWeight()); rPattern.SetItalic(rAttr.GetItalic()); rPattern.SetPitch(rAttr.GetPitch()); rPattern.SetWidthType(rAttr.GetWidthType()); SalData* pSalData = GetSalData(); if (pSalData->mpFontList) rPattern.mpFontData = pSalData->mpFontList->GetFontDataFromId(reinterpret_cast<sal_IntPtr>(pDesc)); CFRelease(pFallback); } CFRelease(pStr); }
I'll take it a look but if you've got time, you can give it a try by adding this line in vcl/quartz/salgdi.cxx: CFRelease(pDesc); after this line: CFRelease(pFallback);
Julien Nabet committed a patch related to this issue. It has been pushed to "master": http://cgit.freedesktop.org/libreoffice/core/commit/?id=986cd454b2a39ac380b137148f944c0d5ead2631 tdf#111497: fix leak in FindFontSubstitute with CFRelease It will be available in 6.0.0. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.
For 5.4, there's https://gerrit.libreoffice.org/#/c/40896/ waiting for review.
Confirmed fixed in Version: 6.0.0.0.alpha0+ Build ID: 9f2a105aa1467224b662980f6d1c4a42e5d8bdfe CPU threads: 4; OS: Mac OS X 10.12.6; UI render: default; Locale: fr-FR (fr_FR.UTF-8); Calc: group Nice work Julien !
(In reply to Alex Thurgood from comment #6) > ... > Nice work Julien ! He! You and your analysis tool made 99% of the work! :-) If you find other things like this, don't hesitate to put me in cc.
Julien Nabet committed a patch related to this issue. It has been pushed to "libreoffice-5-4": http://cgit.freedesktop.org/libreoffice/core/commit/?id=1756d2145e7ab70f5bb32a8343f5b1e4869bd0ee&h=libreoffice-5-4 tdf#111497: fix leak in FindFontSubstitute with CFRelease It will be available in 5.4.1. The patch should be included in the daily builds available at http://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More information about daily builds can be found at: http://wiki.documentfoundation.org/Testing_Daily_Builds Affected users are encouraged to test the fix and report feedback.