summaryrefslogtreecommitdiffstats
path: root/libs/minikin/FontFamily.cpp
diff options
context:
space:
mode:
authorRaph Levien <raph@google.com>2014-05-19 13:21:21 -0700
committerRaph Levien <raph@google.com>2014-05-19 14:01:37 -0700
commitc31e3883456e018d742e9f29815ba5ff8b315ea1 (patch)
treeca0e5d7f03ad7a06496c89c432220d5f08c0d80e /libs/minikin/FontFamily.cpp
parenta3998d4f51e862f00b3dc6b8b99cfbeea2622b2d (diff)
downloadandroid_frameworks_minikin-c31e3883456e018d742e9f29815ba5ff8b315ea1.tar.gz
android_frameworks_minikin-c31e3883456e018d742e9f29815ba5ff8b315ea1.tar.bz2
android_frameworks_minikin-c31e3883456e018d742e9f29815ba5ff8b315ea1.zip
Fix incomplete refcounting and locking
These changes were supposed to be committed in the previous patch "Better refcounting and locking" but seem to have gotten lost in a rebase. It fixes a memory leak and some possible race conditions. Change-Id: I54ca1e37500ec49756fe317cc6d6d03da9911501
Diffstat (limited to 'libs/minikin/FontFamily.cpp')
-rw-r--r--libs/minikin/FontFamily.cpp11
1 files changed, 9 insertions, 2 deletions
diff --git a/libs/minikin/FontFamily.cpp b/libs/minikin/FontFamily.cpp
index d8525ff..d818f77 100644
--- a/libs/minikin/FontFamily.cpp
+++ b/libs/minikin/FontFamily.cpp
@@ -19,6 +19,8 @@
#include <cutils/log.h>
#include <stdlib.h>
#include <stdint.h>
+
+#include "MinikinInternal.h"
#include <minikin/MinikinFont.h>
#include <minikin/AnalyzeStyle.h>
#include <minikin/FontFamily.h>
@@ -35,6 +37,7 @@ FontFamily::~FontFamily() {
}
bool FontFamily::addFont(MinikinFont* typeface) {
+ AutoMutex _l(gMinikinLock);
const uint32_t os2Tag = MinikinFont::MakeTag('O', 'S', '/', '2');
size_t os2Size = 0;
bool ok = typeface->GetTable(os2Tag, NULL, &os2Size);
@@ -47,7 +50,7 @@ bool FontFamily::addFont(MinikinFont* typeface) {
if (analyzeStyle(os2Data.get(), os2Size, &weight, &italic)) {
//ALOGD("analyzed weight = %d, italic = %s", weight, italic ? "true" : "false");
FontStyle style(weight, italic);
- addFont(typeface, style);
+ addFontLocked(typeface, style);
return true;
} else {
ALOGD("failed to analyze style");
@@ -56,7 +59,11 @@ bool FontFamily::addFont(MinikinFont* typeface) {
}
void FontFamily::addFont(MinikinFont* typeface, FontStyle style) {
- typeface->RefLocked();
+ AutoMutex _l(gMinikinLock);
+ addFontLocked(typeface, style);
+}
+
+void FontFamily::addFontLocked(MinikinFont* typeface, FontStyle style) { typeface->RefLocked();
mFonts.push_back(Font(typeface, style));
}