From: Patrick Lam Date: Wed, 25 Jan 2006 14:52:49 +0000 (+0000) Subject: Fix additional memory leaks reported by Ronny V. Vindenes: don't invoke X-Git-Tag: fc-2_3_94~61 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=575a37b7975656f73162438635b4ba26e229b33f;p=fontconfig.git Fix additional memory leaks reported by Ronny V. Vindenes: don't invoke FcValueSave on hashed static strings in FcPatternAddWithBinding. Add another st_dev check in FcDirCacheOpen. --- diff --git a/ChangeLog b/ChangeLog index a851906..cad05d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,14 @@ +2006-01-25 Patrick Lam + * src/fccache.c (FcDirCacheOpen, FcDirCacheWrite): + * src/fccfg.c (FcConfigEvaluate): + * src/fcfreetype.c (FcPatternAddWithBinding): + + Fix additional memory leaks reported by Ronny V. Vindenes: don't + invoke FcValueSave on hashed static strings in + FcPatternAddWithBinding. + + Add another st_dev check in FcDirCacheOpen. + 2006-01-24 James Su reviewed by: plam diff --git a/src/fccache.c b/src/fccache.c index 688da87..742e9aa 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -900,7 +900,10 @@ FcDirCacheOpen (const FcChar8 *dir) cache_hashed = FcDirCacheHashName (cache_file, collisions++); if (!cache_hashed) + { + FcStrFree ((FcChar8 *)cache_file); return -1; + } if (fd > 0) close (fd); @@ -908,7 +911,10 @@ FcDirCacheOpen (const FcChar8 *dir) FcStrFree ((FcChar8 *)cache_hashed); if (fd == -1) + { + FcStrFree ((FcChar8 *)cache_file); return -1; + } FcCacheReadString (fd, name_buf, sizeof (name_buf)); if (!strlen(name_buf)) goto bail; @@ -920,11 +926,13 @@ FcDirCacheOpen (const FcChar8 *dir) continue; } FcStrFree (name_buf_dir); - found = c.st_ino == dir_stat.st_ino; + found = (c.st_ino == dir_stat.st_ino) && (c.st_dev == dir_stat.st_dev); } while (!found); + FcStrFree ((FcChar8 *)cache_file); return fd; bail: + FcStrFree ((FcChar8 *)cache_file); close (fd); return -1; } @@ -1200,6 +1208,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) if (!FcAtomicReplaceOrig(atomic)) goto bail5; FcStrFree ((FcChar8 *)cache_hashed); + FcStrFree ((FcChar8 *)cache_file); FcAtomicUnlock (atomic); FcAtomicDestroy (atomic); return FcTrue; @@ -1216,7 +1225,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) FcStrFree ((FcChar8 *)cache_hashed); bail0: unlink ((char *)cache_file); - free (cache_file); + FcStrFree ((FcChar8 *)cache_file); if (current_dir_block) free (current_dir_block); bail: diff --git a/src/fccfg.c b/src/fccfg.c index c830444..2135d67 100644 --- a/src/fccfg.c +++ b/src/fccfg.c @@ -827,7 +827,6 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) case FcOpString: v.type = FcTypeString; v.u.s = FcStrStaticName(e->u.sval); - v = FcValueSave (v); break; case FcOpMatrix: v.type = FcTypeMatrix; @@ -847,7 +846,7 @@ FcConfigEvaluate (FcPattern *p, FcExpr *e) r = FcPatternGet (p, e->u.field, 0, &v); if (r != FcResultMatch) v.type = FcTypeVoid; - v = FcValueSave (v); + v = FcValueSave (v); break; case FcOpConst: if (FcNameConstant (e->u.constant, &v.u.i)) diff --git a/src/fcpat.c b/src/fcpat.c index aa1e8d6..0a6241b 100644 --- a/src/fcpat.c +++ b/src/fcpat.c @@ -874,7 +874,14 @@ FcPatternAddWithBinding (FcPattern *p, new = FcValueListPtrCreateDynamic(newp); FcMemAlloc (FC_MEM_VALLIST, sizeof (FcValueList)); /* dup string */ - value = FcValueSave (value); + if (value.type == FcTypeString) + { + value.u.s = FcStrStaticName (value.u.s); + if (!value.u.s) + value.type = FcTypeVoid; + } + else + value = FcValueSave (value); if (value.type == FcTypeVoid) goto bail1;