Skip to content

Commit e0d558a

Browse files
Fabrice Di MeglioAndroid (Google) Code Review
authored andcommitted
Merge "Fix potential leak in TextLayouCache"
2 parents 42b04f6 + e74fef3 commit e0d558a

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

core/jni/android/graphics/TextLayoutCache.cpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,22 @@ TextLayoutCacheKey::TextLayoutCacheKey(const SkPaint* paint,
236236
hinting = paint->getHinting();
237237
}
238238

239+
TextLayoutCacheKey::TextLayoutCacheKey(const TextLayoutCacheKey& other) :
240+
text(NULL),
241+
textCopy(other.textCopy),
242+
contextCount(other.contextCount),
243+
dirFlags(other.dirFlags),
244+
typeface(other.typeface),
245+
textSize(other.textSize),
246+
textSkewX(other.textSkewX),
247+
textScaleX(other.textScaleX),
248+
flags(other.flags),
249+
hinting(other.hinting) {
250+
if (other.text) {
251+
textCopy.setTo(other.text);
252+
}
253+
}
254+
239255
bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const {
240256
LTE_INT(count) {
241257
LTE_INT(contextCount) {
@@ -247,7 +263,7 @@ bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const {
247263
LTE_INT(flags) {
248264
LTE_INT(hinting) {
249265
LTE_INT(dirFlags) {
250-
return strncmp16(text, rhs.text, contextCount) < 0;
266+
return strncmp16(getText(), rhs.getText(), contextCount) < 0;
251267
}
252268
}
253269
}
@@ -263,7 +279,7 @@ bool TextLayoutCacheKey::operator<(const TextLayoutCacheKey& rhs) const {
263279

264280
void TextLayoutCacheKey::internalTextCopy() {
265281
textCopy.setTo(text, contextCount);
266-
text = textCopy.string();
282+
text = NULL;
267283
}
268284

269285
size_t TextLayoutCacheKey::getSize() {

core/jni/android/graphics/TextLayoutCache.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ class TextLayoutCacheKey {
7272
const UChar* text, size_t start, size_t count,
7373
size_t contextCount, int dirFlags);
7474

75+
TextLayoutCacheKey(const TextLayoutCacheKey& other);
76+
7577
bool operator<(const TextLayoutCacheKey& rhs) const;
7678

7779
/**
@@ -86,7 +88,7 @@ class TextLayoutCacheKey {
8688
size_t getSize();
8789

8890
private:
89-
const UChar* text;
91+
const UChar* text; // if text is NULL, use textCopy
9092
String16 textCopy;
9193
size_t start;
9294
size_t count;
@@ -98,6 +100,10 @@ class TextLayoutCacheKey {
98100
SkScalar textScaleX;
99101
uint32_t flags;
100102
SkPaint::Hinting hinting;
103+
104+
inline const UChar* getText() const {
105+
return text ? text : textCopy.string();
106+
}
101107
}; // TextLayoutCacheKey
102108

103109
/*

0 commit comments

Comments
 (0)