]> git.wh0rd.org Git - fontconfig.git/commitdiff
Fix additional memory leaks reported by Ronny V. Vindenes: don't invoke
authorPatrick Lam <plam@MIT.EDU>
Wed, 25 Jan 2006 14:52:49 +0000 (14:52 +0000)
committerPatrick Lam <plam@MIT.EDU>
Wed, 25 Jan 2006 14:52:49 +0000 (14:52 +0000)
    FcValueSave on hashed static strings in FcPatternAddWithBinding.
Add another st_dev check in FcDirCacheOpen.

ChangeLog
src/fccache.c
src/fccfg.c
src/fcpat.c

index a851906b9c65b0d365d85f852ecc69996a67b076..cad05d36486960785b3b36772105697c1d71ae72 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2006-01-25  Patrick Lam  <plam@mit.edu>
+       * 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  <james.su@gmail.com>
        reviewed by: plam
        
index 688da877ef1e66f45c2cb8a4e491498982389b65..742e9aa950efa23b91827598f0a546a48a5b2b8c 100644 (file)
@@ -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:
index c830444b127d8902c6fc49263a3919f1c03d6cf0..2135d67f790316cdf4aaa5525ccac98b2d5f4342 100644 (file)
@@ -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))
index aa1e8d6bffef8088e5d0b4f7ce718a6e1bc45dc7..0a6241b564184f37f9688487804f256a8762a871 100644 (file)
@@ -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;