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
|
500 | 500 | uint32 block = 0; |
501 | 501 | const uint8 BITS_PER_BLOCK = 32; |
502 | 502 | uint32 currentCodePoint = 0; |
503 | | |
| 503 | |
| 504 | if (baseCodePoint > kUnicodeBlockMap[kNumUnicodeBlockRanges-1].end) |
| 505 | return; |
| 506 | |
504 | 507 | for (int i = 0; i < FC_CHARSET_MAP_SIZE; ++i) { |
505 | 508 | FcChar32 curMapBlock = charMap[i]; |
506 | 509 | int32 rangeStart = -1; |
507 | 510 | int32 startBlock = -1; |
508 | 511 | int32 endBlock = -1; |
509 | 512 | uint32 startPoint = 0; |
510 | | |
| 513 | |
511 | 514 | 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) { |
514 | 517 | if (curMapBlock == 0 && startBlock < 0) |
515 | 518 | // if no more bits are set then short-circuit the loop |
516 | 519 | break; |
517 | | |
| 520 | |
518 | 521 | if ((curMapBlock & 0x1) != 0 && rangeStart < 0) { |
519 | 522 | rangeStart = bit; |
520 | 523 | startPoint = currentCodePoint + rangeStart; |
… |
… |
ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM
|
522 | 525 | if (startBlock >= 0) { |
523 | 526 | blocksForMap = blocksForMap |
524 | 527 | | kUnicodeBlockMap[startBlock].block; |
525 | | } |
| 528 | } |
526 | 529 | } else if (rangeStart >= 0 && startBlock >= 0) { |
527 | 530 | // when we find an empty bit, that's the end of the range |
528 | 531 | uint32 endPoint = currentCodePoint + (bit - 1); |
… |
… |
ParseFcMap(FcChar32 charMap[], FcChar32 baseCodePoint, unicode_block& blocksForM
|
546 | 549 | startBlock = -1; |
547 | 550 | endBlock = -1; |
548 | 551 | rangeStart = -1; |
549 | | } |
| 552 | } |
550 | 553 | |
551 | 554 | curMapBlock >>= 1; |
552 | 555 | } |
553 | | |
| 556 | |
554 | 557 | if (rangeStart >= 0 && startBlock >= 0) { |
555 | 558 | // if we hit the end of the block and had |
556 | 559 | // found a start of the range then we |
… |
… |
ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)
|
597 | 600 | return B_ERROR; |
598 | 601 | |
599 | 602 | FcCharSet *charSet = FcFreeTypeCharSet(face, NULL); |
600 | | if (charSet == NULL) |
| 603 | if (charSet == NULL) { |
| 604 | PutTransformedFace(face); |
601 | 605 | return B_ERROR; |
| 606 | } |
602 | 607 | |
603 | 608 | FcChar32 charMap[FC_CHARSET_MAP_SIZE]; |
604 | 609 | FcChar32 next = 0; |
… |
… |
ServerFont::GetUnicodeBlocks(unicode_block& blocksForFont)
|
609 | 614 | baseCodePoint = FcCharSetNextPage(charSet, charMap, &next); |
610 | 615 | } |
611 | 616 | |
| 617 | FcCharSetDestroy(charSet); |
| 618 | PutTransformedFace(face); |
612 | 619 | #endif // FONTCONFIG_ENABLED |
613 | 620 | |
614 | 621 | return B_OK; |
… |
… |
ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)
|
633 | 640 | return B_ERROR; |
634 | 641 | |
635 | 642 | FcCharSet *charSet = FcFreeTypeCharSet(face, NULL); |
636 | | if (charSet == NULL) |
| 643 | if (charSet == NULL) { |
| 644 | PutTransformedFace(face); |
637 | 645 | return B_ERROR; |
| 646 | } |
638 | 647 | |
639 | 648 | uint32 curCodePoint = start; |
640 | 649 | |
… |
… |
ServerFont::IncludesUnicodeBlock(uint32 start, uint32 end, bool& hasBlock)
|
649 | 658 | ++curCodePoint; |
650 | 659 | } |
651 | 660 | |
| 661 | FcCharSetDestroy(charSet); |
| 662 | PutTransformedFace(face); |
652 | 663 | #endif // FONTCONFIG_ENABLED |
653 | 664 | |
654 | 665 | return B_OK; |