From: Patrick Lam Date: Mon, 5 Dec 2005 16:08:01 +0000 (+0000) Subject: Don't free strings that have been returned from FcStrStaticName. X-Git-Tag: fc-2_3_93~9 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=9ede93f1dc375c1f4d7e71d821887c01a367d995;p=fontconfig.git Don't free strings that have been returned from FcStrStaticName. --- diff --git a/ChangeLog b/ChangeLog index d86eda3..a367294 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-12-05 Patrick Lam + * src/fcpat.c (FcValueDestroy, FcValueListDestroy, FcStrHashed): + + Don't free strings that have been returned from FcStrStaticName. + 2005-12-01 Patrick Lam * fc-cat/fc-cat.c (FcCacheGlobalFileReadAndPrint, main): diff --git a/src/fcpat.c b/src/fcpat.c index 834bb5e..a626ab6 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -36,6 +36,8 @@ static int fcvaluelist_bank_count = 0, fcvaluelist_ptr, fcvaluelist_count; static FcPatternEltPtr FcPatternEltPtrCreateDynamic (FcPatternElt * e); +static FcBool +FcStrHashed (const FcChar8 *name); static const char * FcPatternFindFullFname (const FcPattern *p); @@ -69,7 +71,8 @@ FcValueDestroy (FcValue v) { switch (v.type) { case FcTypeString: - FcStrFree ((FcChar8 *) v.u.s); + if (!FcStrHashed (v.u.s)) + FcStrFree ((FcChar8 *) v.u.s); break; case FcTypeMatrix: FcMatrixFree ((FcMatrix *) v.u.m); @@ -150,7 +153,8 @@ FcValueListDestroy (FcValueListPtr l) { switch (FcValueListPtrU(l)->value.type) { case FcTypeString: - FcStrFree ((FcChar8 *)FcValueListPtrU(l)->value.u.s); + if (!FcStrHashed ((FcChar8 *)FcValueListPtrU(l)->value.u.s)) + FcStrFree ((FcChar8 *)FcValueListPtrU(l)->value.u.s); break; case FcTypeMatrix: FcMatrixFree ((FcMatrix *)FcValueListPtrU(l)->value.u.m); @@ -1365,6 +1369,19 @@ static struct objectBucket { FcChar32 hash; } *FcObjectBuckets[OBJECT_HASH_SIZE]; +static FcBool +FcStrHashed (const FcChar8 *name) +{ + FcChar32 hash = FcStringHash (name); + struct objectBucket **p; + struct objectBucket *b; + + for (p = &FcObjectBuckets[hash % OBJECT_HASH_SIZE]; (b = *p); p = &(b->next)) + if (b->hash == hash && !strcmp ((char *)name, (char *) (b + 1))) + return FcTrue; + return FcFalse; +} + const FcChar8 * FcStrStaticName (const FcChar8 *name) {