diff options
author | Caolán McNamara <caolanm@redhat.com> | 2017-03-08 15:23:07 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2017-03-08 15:43:06 +0000 |
commit | 7ae797878e1c46a3e39e03932ea4c970fa76f5ab (patch) | |
tree | a44e7b1eb6d9d92abe5c80be46e6fe55ba4ed906 /vcl/unx | |
parent | 29cb3bfc07f42c216b7bbd66d3c8ad14822d49fe (diff) |
valgrind: fix leak
Change-Id: I174225a93a15a5300a94347faf9132f01e52cfe7
Diffstat (limited to 'vcl/unx')
-rw-r--r-- | vcl/unx/generic/fontmanager/fontconfig.cxx | 50 | ||||
-rw-r--r-- | vcl/unx/generic/fontmanager/fontmanager.cxx | 45 |
2 files changed, 42 insertions, 53 deletions
diff --git a/vcl/unx/generic/fontmanager/fontconfig.cxx b/vcl/unx/generic/fontmanager/fontconfig.cxx index 120a116bcfb4..49cfc23d5311 100644 --- a/vcl/unx/generic/fontmanager/fontconfig.cxx +++ b/vcl/unx/generic/fontmanager/fontconfig.cxx @@ -545,7 +545,7 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS // see if this font is already cached // update attributes - std::list< PrintFont* > aFonts; + std::list<std::unique_ptr<PrintFont>> aFonts; OString aDir, aBase, aOrgPath( reinterpret_cast<char*>(file) ); splitPath( aOrgPath, aDir, aBase ); @@ -560,13 +560,11 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS if (eFormatRes != FcResultMatch) format = nullptr; analyzeFontFile( nDirID, aBase, aFonts, reinterpret_cast<char*>(format) ); + if(aFonts.empty()) + { #if OSL_DEBUG_LEVEL > 1 - if( aFonts.empty() ) fprintf( stderr, "Warning: file \"%s\" is unusable to psprint\n", aOrgPath.getStr() ); #endif - - if( aFonts.empty() ) - { //remove font, reuse index //we want to remove unusable fonts here, in case there is a usable font //which duplicates the properties of the unusable one @@ -577,63 +575,65 @@ void PrintFontManager::countFontconfigFonts( std::unordered_map<OString, int, OS continue; } - OUString aFamilyName = OStringToOUString(OString(reinterpret_cast<char*>(family)), RTL_TEXTENCODING_UTF8); - PrintFont* pUpdate = aFonts.front(); - std::list<PrintFont*>::const_iterator second_font = aFonts.begin(); + std::unique_ptr<PrintFont> xUpdate; + + auto second_font = aFonts.begin(); ++second_font; - if( second_font != aFonts.end() ) // more than one font + if (second_font == aFonts.end()) // one font + xUpdate = std::move(aFonts.front()); + else // more than one font { // a collection entry, get the correct index if( eIndexRes == FcResultMatch && nCollectionEntry != -1 ) { - for( std::list< PrintFont* >::iterator it = aFonts.begin(); it != aFonts.end(); ++it ) + for (auto it = aFonts.begin(); it != aFonts.end(); ++it) { if( (*it)->m_nCollectionEntry == nCollectionEntry ) { - pUpdate = *it; + xUpdate = std::move(*it); break; } } + } + + if (xUpdate) + { // update collection entry // additional entries will be created in the cache // if this is a new index (that is if the loop above // ran to the end of the list) - pUpdate->m_nCollectionEntry = nCollectionEntry; + xUpdate->m_nCollectionEntry = nCollectionEntry; } +#if OSL_DEBUG_LEVEL > 1 else { -#if OSL_DEBUG_LEVEL > 1 fprintf( stderr, "multiple fonts for file, but no index in fontconfig pattern ! (index res = %d collection entry = %d\nfile will not be used\n", eIndexRes, nCollectionEntry ); -#endif // we have found more than one font in this file // but fontconfig will not tell us which index is meant // -> something is in disorder, do not use this font - pUpdate = nullptr; } +#endif } - if( pUpdate ) + if (xUpdate) { // set family name - if( pUpdate->m_aFamilyName != aFamilyName ) - { - } if( eWeightRes == FcResultMatch ) - pUpdate->m_eWeight = convertWeight(weight); + xUpdate->m_eWeight = convertWeight(weight); if( eWidthRes == FcResultMatch ) - pUpdate->m_eWidth = convertWidth(width); + xUpdate->m_eWidth = convertWidth(width); if( eSpacRes == FcResultMatch ) - pUpdate->m_ePitch = convertSpacing(spacing); + xUpdate->m_ePitch = convertSpacing(spacing); if( eSlantRes == FcResultMatch ) - pUpdate->m_eItalic = convertSlant(slant); + xUpdate->m_eItalic = convertSlant(slant); if( eStyleRes == FcResultMatch ) { - pUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 ); + xUpdate->m_aStyleName = OStringToOUString( OString( reinterpret_cast<char*>(style) ), RTL_TEXTENCODING_UTF8 ); } // sort into known fonts fontID aFont = m_nNextFontID++; - m_aFonts[ aFont ] = pUpdate; + m_aFonts[ aFont ] = xUpdate.release(); m_aFontFileToFontID[ aBase ].insert( aFont ); #if OSL_DEBUG_LEVEL > 1 nFonts++; diff --git a/vcl/unx/generic/fontmanager/fontmanager.cxx b/vcl/unx/generic/fontmanager/fontmanager.cxx index 6812f2a5a4e8..5efceb8bec49 100644 --- a/vcl/unx/generic/fontmanager/fontmanager.cxx +++ b/vcl/unx/generic/fontmanager/fontmanager.cxx @@ -183,14 +183,13 @@ std::vector<fontID> PrintFontManager::addFontFile( const OString& rFileName ) std::vector<fontID> aFontIds = findFontFileIDs( nDirID, aName ); if( aFontIds.empty() ) { - ::std::list< PrintFont* > aNewFonts; - if( analyzeFontFile( nDirID, aName, aNewFonts ) ) + std::list<std::unique_ptr<PrintFont>> aNewFonts; + if (analyzeFontFile(nDirID, aName, aNewFonts)) { - for( ::std::list< PrintFont* >::iterator it = aNewFonts.begin(); - it != aNewFonts.end(); ++it ) + for (auto it = aNewFonts.begin(); it != aNewFonts.end(); ++it) { fontID nFontId = m_nNextFontID++; - m_aFonts[nFontId] = *it; + m_aFonts[nFontId] = it->release(); m_aFontFileToFontID[ aName ].insert( nFontId ); aFontIds.push_back(nFontId); } @@ -204,7 +203,7 @@ enum fontFormat UNKNOWN, TRUETYPE, CFF }; -bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, ::std::list< PrintFontManager::PrintFont* >& rNewFonts, const char *pFormat ) const +bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, std::list<std::unique_ptr<PrintFontManager::PrintFont>>& rNewFonts, const char *pFormat ) const { rNewFonts.clear(); @@ -275,34 +274,24 @@ bool PrintFontManager::analyzeFontFile( int nDirID, const OString& rFontFile, :: for( int i = 0; i < nLength; i++ ) { - PrintFont* pFont = new PrintFont(); - pFont->m_nDirectory = nDirID; - pFont->m_aFontFile = rFontFile; - pFont->m_nCollectionEntry = i; - if (!analyzeSfntFile(pFont)) - { - delete pFont; - pFont = nullptr; - } - else - rNewFonts.push_back( pFont ); + std::unique_ptr<PrintFont> xFont(new PrintFont); + xFont->m_nDirectory = nDirID; + xFont->m_aFontFile = rFontFile; + xFont->m_nCollectionEntry = i; + if (analyzeSfntFile(xFont.get())) + rNewFonts.push_back(std::move(xFont)); } } else { - PrintFont* pFont = new PrintFont(); - pFont->m_nDirectory = nDirID; - pFont->m_aFontFile = rFontFile; - pFont->m_nCollectionEntry = 0; + std::unique_ptr<PrintFont> xFont(new PrintFont); + xFont->m_nDirectory = nDirID; + xFont->m_aFontFile = rFontFile; + xFont->m_nCollectionEntry = 0; // need to read the font anyway to get aliases inside the font file - if (!analyzeSfntFile(pFont)) - { - delete pFont; - pFont = nullptr; - } - else - rNewFonts.push_back( pFont ); + if (analyzeSfntFile(xFont.get())) + rNewFonts.push_back(std::move(xFont)); } } return ! rNewFonts.empty(); |