Ticket #13526: 0001-Critical-cleanup-code-for-GetUnicodeBlocks-and-Inclu.patch

File 0001-Critical-cleanup-code-for-GetUnicodeBlocks-and-Inclu.patch, 3.4 KB (added by dsizzle, 7 years ago)

Patch to fix critical lock issue and memory leaks

  • src/servers/app/ServerFont.cpp

    From dead660ccee8bf3985f1026e0519ccdf5893e775 Mon Sep 17 00:00:00 2001
    From: Dale Cieslak <dcieslak@yahoo.com>
    Date: Sun, 28 May 2017 16:36:51 +0000
    Subject: [PATCH] Critical cleanup code for 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.
    ---
     src/servers/app/ServerFont.cpp | 31 +++++++++++++++++++++----------
     1 file changed, 21 insertions(+), 10 deletions(-)
    
    diff --git a/src/servers/app/ServerFont.cpp b/src/servers/app/ServerFont.cpp
    index cd9015c..4cfc92d 100644
    a b ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM  
    500500    uint32 block = 0;
    501501    const uint8 BITS_PER_BLOCK = 32;
    502502    uint32 currentCodePoint = 0;
    503    
     503
     504    if (baseCodePoint > kUnicodeBlockMap[kNumUnicodeBlockRanges-1].end)
     505        return;
     506
    504507    for (int i = 0; i < FC_CHARSET_MAP_SIZE; ++i) {
    505508        FcChar32 curMapBlock = charMap[i];
    506509        int32 rangeStart = -1;
    507510        int32 startBlock = -1;
    508511        int32 endBlock = -1;
    509512        uint32 startPoint = 0;
    510    
     513
    511514        currentCodePoint = baseCodePoint + block;
    512                
    513         for (int bit = 0; bit < BITS_PER_BLOCK; ++bit) {       
     515
     516        for (int bit = 0; bit < BITS_PER_BLOCK; ++bit) {
    514517            if (curMapBlock == 0 && startBlock < 0)
    515518                // if no more bits are set then short-circuit the loop
    516519                break;
    517            
     520
    518521            if ((curMapBlock & 0x1) != 0 && rangeStart < 0) {
    519522                rangeStart = bit;
    520523                startPoint = currentCodePoint + rangeStart;
    ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM  
    522525                if (startBlock >= 0) {
    523526                    blocksForMap = blocksForMap
    524527                        | kUnicodeBlockMap[startBlock].block;
    525                 } 
     528                }
    526529            } else if (rangeStart >= 0 && startBlock >= 0) {
    527530                    // when we find an empty bit, that's the end of the range
    528531                uint32 endPoint = currentCodePoint + (bit - 1);
    ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM  
    546549                startBlock = -1;
    547550                endBlock = -1;
    548551                rangeStart = -1;
    549             } 
     552            }
    550553
    551554            curMapBlock >>= 1;
    552555        }
    553        
     556
    554557        if (rangeStart >= 0 && startBlock >= 0) {
    555558                // if we hit the end of the block and had
    556559                // found a start of the range then we
    ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)  
    597600        return B_ERROR;
    598601
    599602    FcCharSet *charSet = FcFreeTypeCharSet(face, NULL);
    600     if (charSet == NULL)
     603    if (charSet == NULL) {
     604        PutTransformedFace(face);
    601605        return B_ERROR;
     606    }
    602607
    603608    FcChar32 charMap[FC_CHARSET_MAP_SIZE];
    604609    FcChar32 next = 0;
    ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)  
    609614        baseCodePoint = FcCharSetNextPage(charSet, charMap, &next);
    610615    }
    611616
     617    FcCharSetDestroy(charSet);
     618    PutTransformedFace(face);
    612619#endif // FONTCONFIG_ENABLED
    613620
    614621    return B_OK;
    ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)  
    633640        return B_ERROR;
    634641
    635642    FcCharSet *charSet = FcFreeTypeCharSet(face, NULL);
    636     if (charSet == NULL)
     643    if (charSet == NULL) {
     644        PutTransformedFace(face);
    637645        return B_ERROR;
     646    }
    638647
    639648    uint32 curCodePoint = start;
    640649
    ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)  
    649658        ++curCodePoint;
    650659    }
    651660
     661    FcCharSetDestroy(charSet);
     662    PutTransformedFace(face);
    652663#endif // FONTCONFIG_ENABLED
    653664
    654665    return B_OK;