Fix memory leaks in FcFreeTypeQueryFace

This commit is contained in:
Akira TAGOH 2013-09-09 19:59:31 +09:00
parent 6720892e97
commit a61e145304
1 changed files with 10 additions and 5 deletions

View File

@ -1105,7 +1105,6 @@ FcFreeTypeQueryFace (const FT_Face face,
const char *tmp; const char *tmp;
FcChar8 *hashstr = NULL; FcChar8 *hashstr = NULL;
char *fontdata = NULL;
FT_Error err; FT_Error err;
FT_ULong len = 0, alen; FT_ULong len = 0, alen;
@ -1668,15 +1667,21 @@ FcFreeTypeQueryFace (const FT_Face face,
err = FT_Load_Sfnt_Table (face, 0, 0, NULL, &len); err = FT_Load_Sfnt_Table (face, 0, 0, NULL, &len);
if (err == FT_Err_Ok) if (err == FT_Err_Ok)
{ {
char *fontdata;
alen = (len + 63) & ~63; alen = (len + 63) & ~63;
fontdata = malloc (alen); fontdata = malloc (alen);
if (!fontdata) if (!fontdata)
goto bail3; goto bail3;
err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len); err = FT_Load_Sfnt_Table (face, 0, 0, (FT_Byte *)fontdata, &len);
if (err != FT_Err_Ok) if (err != FT_Err_Ok)
{
free (fontdata);
goto bail3; goto bail3;
}
memset (&fontdata[len], 0, alen - len); memset (&fontdata[len], 0, alen - len);
hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len); hashstr = FcHashGetSHA256DigestFromMemory (fontdata, len);
free (fontdata);
} }
else if (err == FT_Err_Invalid_Face_Handle) else if (err == FT_Err_Invalid_Face_Handle)
{ {
@ -1692,8 +1697,12 @@ FcFreeTypeQueryFace (const FT_Face face,
if (hashstr) if (hashstr)
{ {
if (!FcPatternAddString (pat, FC_HASH, hashstr)) if (!FcPatternAddString (pat, FC_HASH, hashstr))
{
free (hashstr);
goto bail1; goto bail1;
} }
free (hashstr);
}
bail3: bail3:
/* /*
@ -1783,10 +1792,6 @@ bail3:
bail2: bail2:
FcCharSetDestroy (cs); FcCharSetDestroy (cs);
bail1: bail1:
if (hashstr)
free (hashstr);
if (fontdata)
free (fontdata);
FcPatternDestroy (pat); FcPatternDestroy (pat);
bail0: bail0:
return NULL; return NULL;