Fix possible memory leaks in FcPatternObjectAddWithBinding

Reported by Ruth Ivimey-Cook

Fixes https://gitlab.freedesktop.org/fontconfig/fontconfig/-/issues/302
This commit is contained in:
Akira TAGOH 2022-01-31 19:03:29 +09:00
parent 16bbb5340b
commit 875878efb7
1 changed files with 10 additions and 33 deletions

View File

@ -142,27 +142,7 @@ FcValueListDestroy (FcValueListPtr l)
FcValueListPtr next; FcValueListPtr next;
for (; l; l = next) for (; l; l = next)
{ {
switch ((int) l->value.type) { FcValueDestroy (l->value);
case FcTypeString:
FcFree (l->value.u.s);
break;
case FcTypeMatrix:
FcMatrixFree ((FcMatrix *)l->value.u.m);
break;
case FcTypeCharSet:
FcCharSetDestroy
((FcCharSet *) (l->value.u.c));
break;
case FcTypeLangSet:
FcLangSetDestroy
((FcLangSet *) (l->value.u.l));
break;
case FcTypeRange:
FcRangeDestroy ((FcRange *) (l->value.u.r));
break;
default:
break;
}
next = FcValueListNext(l); next = FcValueListNext(l);
free(l); free(l);
} }
@ -708,30 +688,29 @@ FcPatternObjectAddWithBinding (FcPattern *p,
if (!new) if (!new)
goto bail0; goto bail0;
value = FcValueSave (value); new->value = FcValueSave (value);
if (value.type == FcTypeVoid) new->binding = binding;
new->next = NULL;
if (new->value.type == FcTypeVoid)
goto bail1; goto bail1;
/* /*
* Make sure the stored type is valid for built-in objects * Make sure the stored type is valid for built-in objects
*/ */
if (!FcObjectValidType (object, value.type)) if (!FcObjectValidType (object, new->value.type))
{ {
fprintf (stderr, fprintf (stderr,
"Fontconfig warning: FcPattern object %s does not accept value", "Fontconfig warning: FcPattern object %s does not accept value",
FcObjectName (object)); FcObjectName (object));
FcValuePrintFile (stderr, value); FcValuePrintFile (stderr, new->value);
fprintf (stderr, "\n"); fprintf (stderr, "\n");
goto bail1; goto bail1;
} }
new->value = value;
new->binding = binding;
new->next = NULL;
e = FcPatternObjectInsertElt (p, object); e = FcPatternObjectInsertElt (p, object);
if (!e) if (!e)
goto bail2; goto bail1;
if (append) if (append)
{ {
@ -747,10 +726,8 @@ FcPatternObjectAddWithBinding (FcPattern *p,
return FcTrue; return FcTrue;
bail2:
FcValueDestroy (value);
bail1: bail1:
free (new); FcValueListDestroy (new);
bail0: bail0:
return FcFalse; return FcFalse;
} }