Ignore null pointer on Fc*Destroy functions

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/339
This commit is contained in:
Akira TAGOH 2022-12-05 21:40:26 +09:00
parent 6663fe457d
commit ed6c9cf67b
8 changed files with 97 additions and 80 deletions

View File

@ -229,7 +229,8 @@ FcAtomicUnlock (FcAtomic *atomic)
void
FcAtomicDestroy (FcAtomic *atomic)
{
free (atomic);
if (atomic)
free (atomic);
}
#define __fcatomic__
#include "fcaliastail.h"

View File

@ -362,40 +362,43 @@ FcConfigDestroy (FcConfig *config)
FcExprPage *page;
FcMatchKind k;
if (FcRefDec (&config->ref) != 1)
return;
(void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->configMapDirs);
FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->cacheDirs);
FcStrSetDestroy (config->configFiles);
FcStrSetDestroy (config->acceptGlobs);
FcStrSetDestroy (config->rejectGlobs);
FcFontSetDestroy (config->acceptPatterns);
FcFontSetDestroy (config->rejectPatterns);
for (k = FcMatchKindBegin; k < FcMatchKindEnd; k++)
FcPtrListDestroy (config->subst[k]);
FcPtrListDestroy (config->rulesetList);
FcStrSetDestroy (config->availConfigFiles);
for (set = FcSetSystem; set <= FcSetApplication; set++)
if (config->fonts[set])
FcFontSetDestroy (config->fonts[set]);
page = config->expr_pool;
while (page)
if (config)
{
FcExprPage *next = page->next_page;
free (page);
page = next;
}
if (config->sysRoot)
if (FcRefDec (&config->ref) != 1)
return;
(void) fc_atomic_ptr_cmpexch (&_fcConfig, config, NULL);
FcStrSetDestroy (config->configDirs);
FcStrSetDestroy (config->configMapDirs);
FcStrSetDestroy (config->fontDirs);
FcStrSetDestroy (config->cacheDirs);
FcStrSetDestroy (config->configFiles);
FcStrSetDestroy (config->acceptGlobs);
FcStrSetDestroy (config->rejectGlobs);
FcFontSetDestroy (config->acceptPatterns);
FcFontSetDestroy (config->rejectPatterns);
for (k = FcMatchKindBegin; k < FcMatchKindEnd; k++)
FcPtrListDestroy (config->subst[k]);
FcPtrListDestroy (config->rulesetList);
FcStrSetDestroy (config->availConfigFiles);
for (set = FcSetSystem; set <= FcSetApplication; set++)
if (config->fonts[set])
FcFontSetDestroy (config->fonts[set]);
page = config->expr_pool;
while (page)
{
FcExprPage *next = page->next_page;
free (page);
page = next;
}
if (config->sysRoot)
FcStrFree (config->sysRoot);
free (config);
free (config);
}
}
/*
@ -421,7 +424,7 @@ FcConfigAddCache (FcConfig *config, FcCache *cache,
if (fs)
{
int nref = 0;
for (i = 0; i < fs->nfont; i++)
{
FcPattern *font = FcFontSetFont (fs, i);
@ -505,7 +508,7 @@ FcConfigAddDirList (FcConfig *config, FcSetName set, FcStrSet *dirSet)
dirlist = FcStrListCreate (dirSet);
if (!dirlist)
return FcFalse;
while ((dir = FcStrListNext (dirlist)))
{
if (FcDebug () & FC_DBG_FONTSET)
@ -534,7 +537,7 @@ FcConfigBuildFonts (FcConfig *config)
config = FcConfigReference (config);
if (!config)
return FcFalse;
fonts = FcFontSetCreate ();
if (!fonts)
{
@ -1331,7 +1334,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
v.u.b = FcConfigCompareValue (&vl, e->op, &vr);
FcValueDestroy (vl);
FcValueDestroy (vr);
break;
break;
case FcOpOr:
case FcOpAnd:
case FcOpPlus:
@ -1347,7 +1350,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
switch ((int) vle.type) {
case FcTypeDouble:
switch ((int) op) {
case FcOpPlus:
case FcOpPlus:
v.type = FcTypeDouble;
v.u.d = vle.u.d + vre.u.d;
break;
@ -1396,7 +1399,7 @@ FcConfigEvaluate (FcPattern *p, FcPattern *p_pat, FcMatchKind kind, FcExpr *e)
str = FcStrPlus (vle.u.s, vre.u.s);
v.u.s = FcStrdup (str);
FcStrFree (str);
if (!v.u.s)
v.type = FcTypeVoid;
break;
@ -2829,7 +2832,7 @@ FcConfigAppFontAddFile (FcConfig *config,
}
FcConfigSetFonts (config, set, FcSetApplication);
}
if (!FcFileScanConfig (set, subdirs, file, config))
{
FcStrSetDestroy (subdirs);

View File

@ -42,13 +42,16 @@ FcFontSetCreate (void)
void
FcFontSetDestroy (FcFontSet *s)
{
int i;
if (s)
{
int i;
for (i = 0; i < s->nfont; i++)
FcPatternDestroy (s->fonts[i]);
if (s->fonts)
free (s->fonts);
free (s);
for (i = 0; i < s->nfont; i++)
FcPatternDestroy (s->fonts[i]);
if (s->fonts)
free (s->fonts);
free (s);
}
}
FcBool

View File

@ -92,14 +92,17 @@ FcObjectSetDestroy (FcObjectSet *os)
{
int i;
if (os->objects)
if (os)
{
for (i = 0; i < os->nobject; i++)
FcFree (os->objects[i]);
if (os->objects)
{
for (i = 0; i < os->nobject; i++)
FcFree (os->objects[i]);
free ((void *) os->objects);
free ((void *) os->objects);
}
free (os);
}
free (os);
}
FcObjectSet *

View File

@ -533,17 +533,17 @@ FcPatternObjectInsertElt (FcPattern *p, FcObject object)
p->size++;
}
}
e = FcPatternElts(p);
/* move elts up */
memmove (e + i + 1,
e + i,
sizeof (FcPatternElt) *
(FcPatternObjectCount (p) - i));
/* bump count */
p->num++;
e[i].object = object;
e[i].values = NULL;
}
@ -1559,7 +1559,7 @@ FcValueListSerialize (FcSerialize *serialize, const FcValueList *vl)
FcValueList);
else
head_serialized = vl_serialized;
vl_serialized->next = NULL;
vl_serialized->value.type = vl->value.type;
switch ((int) vl->value.type) {

View File

@ -57,15 +57,18 @@ FcPtrListDestroy (FcPtrList *list)
{
FcPtrListIter iter;
FcPtrListIterInit (list, &iter);
do
if (list)
{
if (FcPtrListIterGetValue (list, &iter))
list->destroy_func (FcPtrListIterGetValue (list, &iter));
FcPtrListIterRemove (list, &iter);
} while (FcPtrListIterIsValid (list, &iter));
FcPtrListIterInit (list, &iter);
do
{
if (FcPtrListIterGetValue (list, &iter))
list->destroy_func (FcPtrListIterGetValue (list, &iter));
FcPtrListIterRemove (list, &iter);
} while (FcPtrListIterIsValid (list, &iter));
free (list);
free (list);
}
}
void

View File

@ -56,7 +56,8 @@ FcRangeCreateInteger (FcChar32 begin, FcChar32 end)
void
FcRangeDestroy (FcRange *range)
{
free (range);
if (range)
free (range);
}
FcRange *

View File

@ -122,7 +122,7 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
int mid = (min + max) >> 1;
FcChar32 low = fcCaseFold[mid].upper;
FcChar32 high = low + FcCaseFoldUpperCount (&fcCaseFold[mid]);
if (high <= ucs4)
min = mid + 1;
else if (ucs4 < low)
@ -131,7 +131,7 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
{
const FcCaseFold *fold = &fcCaseFold[mid];
int dlen;
switch (fold->method) {
case FC_CASE_FOLD_EVEN_ODD:
if ((ucs4 & 1) != (fold->upper & 1))
@ -145,10 +145,10 @@ FcStrCaseWalkerLong (FcCaseWalker *w, FcChar8 r)
memcpy (w->utf8, fcCaseFoldChars + fold->offset, dlen);
break;
}
/* consume rest of src utf-8 bytes */
w->src += slen - 1;
/* read from temp buffer */
w->utf8[dlen] = '\0';
w->read = w->utf8;
@ -441,7 +441,7 @@ FcStrContainsWord (const FcChar8 *s1, const FcChar8 *s2)
FcBool wordStart = FcTrue;
int s1len = strlen ((char *) s1);
int s2len = strlen ((char *) s2);
while (s1len >= s2len)
{
if (wordStart &&
@ -684,10 +684,10 @@ FcUtf8ToUcs4 (const FcChar8 *src_orig,
{
result <<= 6;
s = *src++;
if ((s & 0xc0) != 0x80)
return -1;
result |= s & 0x3f;
}
*dst = result;
@ -1590,20 +1590,23 @@ FcStrSetReference (FcStrSet *set)
void
FcStrSetDestroy (FcStrSet *set)
{
int i;
if (set)
{
int i;
/* We rely on this in FcGetDefaultLangs for caching. */
if (FcRefIsConst (&set->ref))
return;
/* We rely on this in FcGetDefaultLangs for caching. */
if (FcRefIsConst (&set->ref))
return;
if (FcRefDec (&set->ref) != 1)
return;
if (FcRefDec (&set->ref) != 1)
return;
for (i = 0; i < set->num; i++)
FcStrFree (set->strs[i]);
if (set->strs)
free (set->strs);
free (set);
for (i = 0; i < set->num; i++)
FcStrFree (set->strs[i]);
if (set->strs)
free (set->strs);
free (set);
}
}
FcStrList *