Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(644)

Unified Diff: src/ports/SkFontConfigParser_android.cpp

Issue 226183002: Prevent potential leaking of memory by using SkString and SkTArray. (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/ports/SkFontConfigParser_android.cpp
diff --git a/src/ports/SkFontConfigParser_android.cpp b/src/ports/SkFontConfigParser_android.cpp
index 73de73bb54ea4f4e3526c3516a48bd605b930f52..38a6ee652065cf25160d291065659125042a8d7a 100644
--- a/src/ports/SkFontConfigParser_android.cpp
+++ b/src/ports/SkFontConfigParser_android.cpp
@@ -52,18 +52,13 @@ static void textHandler(void *data, const char *s, int len) {
// Make sure we're in the right state to store this name information
if (familyData->currentFamily &&
(familyData->currentTag == NAMESET_TAG || familyData->currentTag == FILESET_TAG)) {
- // Malloc new buffer to store the string
- char *buff;
- buff = (char*) malloc((len + 1) * sizeof(char));
- strncpy(buff, s, len);
- buff[len] = '\0';
switch (familyData->currentTag) {
case NAMESET_TAG:
- *(familyData->currentFamily->fNames.append()) = buff;
+ familyData->currentFamily->fNames.push_back().set(s, len);
break;
case FILESET_TAG:
if (familyData->currentFontInfo) {
- familyData->currentFontInfo->fFileName = buff;
+ familyData->currentFontInfo->fFileName.set(s, len);
}
break;
default:
@@ -78,7 +73,8 @@ static void textHandler(void *data, const char *s, int len) {
* variants then lets textHandler handle the actual file name
*/
static void fontFileElementHandler(FamilyData *familyData, const char **attributes) {
- FontFileInfo* newFileInfo = new FontFileInfo();
+
+ FontFileInfo& newFileInfo = familyData->currentFamily->fFontFiles.push_back();
if (attributes) {
int currentAttributeIndex = 0;
while (attributes[currentAttributeIndex]) {
@@ -88,19 +84,18 @@ static void fontFileElementHandler(FamilyData *familyData, const char **attribut
int valueLength = strlen(attributeValue);
if (strncmp(attributeName, "variant", nameLength) == 0) {
if (strncmp(attributeValue, "elegant", valueLength) == 0) {
- newFileInfo->fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant);
+ newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kElegant_Variant);
} else if (strncmp(attributeValue, "compact", valueLength) == 0) {
- newFileInfo->fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kCompact_Variant);
+ newFileInfo.fPaintOptions.setFontVariant(SkPaintOptionsAndroid::kCompact_Variant);
}
} else if (strncmp(attributeName, "lang", nameLength) == 0) {
- newFileInfo->fPaintOptions.setLanguage(attributeValue);
+ newFileInfo.fPaintOptions.setLanguage(attributeValue);
}
//each element is a pair of attributeName/attributeValue string pairs
currentAttributeIndex += 2;
}
}
- *(familyData->currentFamily->fFontFiles.append()) = newFileInfo;
- familyData->currentFontInfo = newFileInfo;
+ familyData->currentFontInfo = &newFileInfo;
XML_SetCharacterDataHandler(*familyData->parser, textHandler);
}
« no previous file with comments | « src/ports/SkFontConfigParser_android.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698