Don't leak FcValues string loaded through fcxml.c (#17661)

Patch from Caolan McNamara.
This commit is contained in:
Behdad Esfahbod 2008-09-22 18:16:30 -04:00
parent 311da2316f
commit 799691c901
2 changed files with 7 additions and 5 deletions

View File

@ -27,7 +27,7 @@
#include <assert.h> #include <assert.h>
static FcBool static FcBool
FcStrHashed (const FcChar8 *name); FcHashOwnsName(const FcChar8 *name);
FcPattern * FcPattern *
FcPatternCreate (void) FcPatternCreate (void)
@ -50,7 +50,7 @@ FcValueDestroy (FcValue v)
{ {
switch (v.type) { switch (v.type) {
case FcTypeString: case FcTypeString:
if (!FcStrHashed (v.u.s)) if (!FcHashOwnsName(v.u.s))
FcStrFree ((FcChar8 *) v.u.s); FcStrFree ((FcChar8 *) v.u.s);
break; break;
case FcTypeMatrix: case FcTypeMatrix:
@ -131,7 +131,7 @@ FcValueListDestroy (FcValueListPtr l)
{ {
switch (l->value.type) { switch (l->value.type) {
case FcTypeString: case FcTypeString:
if (!FcStrHashed ((FcChar8 *)l->value.u.s)) if (!FcHashOwnsName((FcChar8 *)l->value.u.s))
FcStrFree ((FcChar8 *)l->value.u.s); FcStrFree ((FcChar8 *)l->value.u.s);
break; break;
case FcTypeMatrix: case FcTypeMatrix:
@ -1041,14 +1041,14 @@ static struct objectBucket {
} *FcObjectBuckets[OBJECT_HASH_SIZE]; } *FcObjectBuckets[OBJECT_HASH_SIZE];
static FcBool static FcBool
FcStrHashed (const FcChar8 *name) FcHashOwnsName (const FcChar8 *name)
{ {
FcChar32 hash = FcStringHash (name); FcChar32 hash = FcStringHash (name);
struct objectBucket **p; struct objectBucket **p;
struct objectBucket *b; struct objectBucket *b;
for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next))
if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1))) if (b->hash == hash && ((char *)name == (char *) (b + 1)))
return FcTrue; return FcTrue;
return FcFalse; return FcFalse;
} }

View File

@ -1997,8 +1997,10 @@ FcParsePatelt (FcConfigParse *parse)
if (!FcPatternAdd (pattern, name, value, FcTrue)) if (!FcPatternAdd (pattern, name, value, FcTrue))
{ {
FcConfigMessage (parse, FcSevereError, "out of memory"); FcConfigMessage (parse, FcSevereError, "out of memory");
FcValueDestroy(value);
break; break;
} }
FcValueDestroy(value);
} }
FcVStackPushPattern (parse, pattern); FcVStackPushPattern (parse, pattern);