]> git.wh0rd.org - fontconfig.git/commitdiff
Only load requested fonts for fc-cache, and cleanup memory handling:
authorPatrick Lam <plam@MIT.EDU>
Wed, 31 Aug 2005 15:12:41 +0000 (15:12 +0000)
committerPatrick Lam <plam@MIT.EDU>
Wed, 31 Aug 2005 15:12:41 +0000 (15:12 +0000)
    *Serialize no longer mutates original FcPatterns, it creates a new copy
    in the supplied buffer. Fix thinkos in global cache freeing and in
    FcCacheSkipToArch.

fc-cache/fc-cache.c
src/fccache.c
src/fcfs.c

index 507902f3a547649c70df678d3ba1c91c28094966..fc0c4e511913ca3e90acd3f559281ffc9486d8c8 100644 (file)
@@ -270,8 +270,7 @@ main (int argc, char **argv)
     if (systemOnly)
        FcConfigEnableHome (FcFalse);
     /* need to use FcInitLoadConfig when we use dirs */
-    FcInit ();
-    config = FcConfigGetCurrent ();
+    config = FcInitLoadConfig ();
     if (!config)
     {
        fprintf (stderr, "%s: Can't init font config library\n", argv[0]);
index 77f09c7e63fd49e09486cf98c1a1e6321676f04c..6b6b8e36c54614b7aca380ffc1d748a1ca60cad8 100644 (file)
@@ -110,16 +110,10 @@ FcCacheWriteString (int fd, const FcChar8 *chars)
 static void
 FcGlobalCacheDirDestroy (FcGlobalCacheDir *d)
 {
-    FcGlobalCacheDir   *dd, *next;
-
-    for (dd = d; dd; dd = next)
-    {
-       next = dd->next;
-       FcMemFree (FC_MEM_STRING, strlen (dd->name)+1);
-       free (dd->name);
-       FcMemFree (FC_MEM_CACHE, sizeof (FcGlobalCacheDir));
-       free (dd);
-    }
+    FcMemFree (FC_MEM_STRING, strlen (d->name)+1);
+    free (d->name);
+    FcMemFree (FC_MEM_CACHE, sizeof (FcGlobalCacheDir));
+    free (d);
 }
 
 FcGlobalCache *
@@ -328,10 +322,14 @@ FcGlobalCacheSave (FcGlobalCache    *cache,
 
     for (dir = cache->dirs; dir; dir = dir->next)
     {
-       FcCacheWriteString (fd, dir->name);
-       write (fd, &dir->metadata, sizeof(FcCache));
-       lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET);
-       write (fd, dir->ent, dir->metadata.count);
+        if (dir->ent)
+        {
+            FcCacheWriteString (fd, dir->name);
+            write (fd, &dir->metadata, sizeof(FcCache));
+            lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET);
+            write (fd, dir->ent, dir->metadata.count);
+            free (dir->ent);
+        }
     }
     FcCacheWriteString (fd, "");
 
@@ -388,21 +386,18 @@ FcCacheSkipToArch (int fd, const char * arch)
        lseek (fd, current_arch_start, SEEK_SET);
        if (FcCacheReadString (fd, candidate_arch_machine_name_count, 
                                sizeof (candidate_arch_machine_name_count)) == 0)
-           break;
+            return -1;
        if (!strlen(candidate_arch_machine_name_count))
            return -1;
        bs = strtol(candidate_arch_machine_name_count, &candidate_arch, 16);
        candidate_arch++; /* skip leading space */
 
        if (strcmp (candidate_arch, arch)==0)
-           break;
+           return current_arch_start;
        current_arch_start += bs;
     }
 
-    if (candidate_arch && strcmp (candidate_arch, arch)!=0)
-       return -1;
-
-    return current_arch_start;
+    return -1;
 }
 
 /* Cuts out the segment at the file pointer (moves everything else
@@ -771,6 +766,7 @@ FcDirCacheWrite (FcFontSet *set, const FcChar8 *dir)
     write (fd, &metadata, sizeof(FcCache));
     lseek (fd, FcCacheNextOffset (lseek(fd, 0, SEEK_END)), SEEK_SET);
     write (fd, current_dir_block, metadata.count);
+    free (current_dir_block);
 
     /* this actually serves to pad out the cache file, if needed */
     if (ftruncate (fd, current_arch_start + truncate_to) == -1)
index 90e858082f13d1483b96f744e3fddfd906e5b8f3..3ba567479d1c225291f041670c14e7ae0d5269e3 100644 (file)
@@ -133,9 +133,6 @@ FcFontSetSerialize (int bank, FcFontSet * s)
     {
        p = FcPatternSerialize (bank, s->fonts[i]);
        if (!p) return FcFalse;
-       FcPatternDestroy (s->fonts[i]);
-
-       s->fonts[i] = p;
     }
     FcObjectSerialize();