Memory leaks and locking issues in GetUnicodeBlocks and IncludesUnicodeBlock

- GetTransformedFace *must* be paired with PutTransformedFace otherwise
the font style never gets unlocked.
- Also use FcCharSetDestroy when done with a fontconfig charset to
prevent leaked memory.

Signed-off-by: Adrien Destugues <pulkomandy@pulkomandy.tk>

ticket: #13526
This commit is contained in:
Dale Cieslak 2017-05-28 16:36:51 +00:00 committed by Adrien Destugues
parent c7258f02db
commit 061b9eeccf

View File

@ -501,6 +501,9 @@ ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM
const uint8 BITS_PER_BLOCK = 32;
uint32 currentCodePoint = 0;
if (baseCodePoint > kUnicodeBlockMap[kNumUnicodeBlockRanges-1].end)
return;
for (int i = 0; i < FC_CHARSET_MAP_SIZE; ++i) {
FcChar32 curMapBlock = charMap[i];
int32 rangeStart = -1;
@ -597,8 +600,10 @@ ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)
return B_ERROR;
FcCharSet *charSet = FcFreeTypeCharSet(face, NULL);
if (charSet == NULL)
if (charSet == NULL) {
PutTransformedFace(face);
return B_ERROR;
}
FcChar32 charMap[FC_CHARSET_MAP_SIZE];
FcChar32 next = 0;
@ -609,6 +614,8 @@ ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)
baseCodePoint = FcCharSetNextPage(charSet, charMap, &next);
}
FcCharSetDestroy(charSet);
PutTransformedFace(face);
#endif // FONTCONFIG_ENABLED
return B_OK;
@ -633,8 +640,10 @@ ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)
return B_ERROR;
FcCharSet *charSet = FcFreeTypeCharSet(face, NULL);
if (charSet == NULL)
if (charSet == NULL) {
PutTransformedFace(face);
return B_ERROR;
}
uint32 curCodePoint = start;
@ -649,6 +658,8 @@ ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)
++curCodePoint;
}
FcCharSetDestroy(charSet);
PutTransformedFace(face);
#endif // FONTCONFIG_ENABLED
return B_OK;