]> git.wh0rd.org - fontconfig.git/blobdiff - src/fccache.c
Free temporary string in FcDirCacheUnlink (Bug #11758)
[fontconfig.git] / src / fccache.c
index 11f88a788b2dc84ab5361055aac44f638924ffd7..9e8819cbdc2d111d833353e329e18d635e74e31e 100644 (file)
@@ -104,6 +104,7 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config)
         if (!cache_hashed)
            break;
        (void) unlink ((char *) cache_hashed);
+       FcStrFree (cache_hashed);
     }
     FcStrListDone (list);
     /* return FcFalse if something went wrong */
@@ -213,6 +214,17 @@ struct _FcCacheSkip {
 static FcCacheSkip     *fcCacheChains[FC_CACHE_MAX_LEVEL];
 static int             fcCacheMaxLevel;
 
+#if HAVE_RANDOM
+# define FcRandom()  random()
+#else
+# if HAVE_LRAND48
+#  define FcRandom()  lrand48()
+# else
+#  if HAVE_RAND
+#   define FcRandom()  rand()
+#  endif
+# endif
+#endif
 /*
  * Generate a random level number, distributed
  * so that each level is 1/4 as likely as the one before
@@ -223,7 +235,7 @@ static int
 random_level (void)
 {
     /* tricky bit -- each bit is '1' 75% of the time */
-    long int   bits = random () | random ();
+    long int   bits = FcRandom () | FcRandom ();
     int        level = 0;
 
     while (++level < FC_CACHE_MAX_LEVEL)
@@ -275,9 +287,18 @@ FcCacheInsert (FcCache *cache, struct stat *cache_stat)
     s->cache = cache;
     s->size = cache->size;
     s->ref = 1;
-    s->cache_dev = cache_stat->st_dev;
-    s->cache_ino = cache_stat->st_ino;
-    s->cache_mtime = cache_stat->st_mtime;
+    if (cache_stat)
+    {
+       s->cache_dev = cache_stat->st_dev;
+       s->cache_ino = cache_stat->st_ino;
+       s->cache_mtime = cache_stat->st_mtime;
+    }
+    else
+    {
+       s->cache_dev = 0;
+       s->cache_ino = 0;
+       s->cache_mtime = 0;
+    }
     
     /*
      * Insert into all fcCacheChains
@@ -434,7 +455,8 @@ FcDirCacheMapFd (int fd, struct stat *fd_stat)
                                         PAGE_READONLY, 0, 0, NULL);
            if (hFileMap != NULL)
            {
-               cache = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, 0, size);
+               cache = MapViewOfFile (hFileMap, FILE_MAP_READ, 0, 0, 
+                                      fd_stat->st_size);
                CloseHandle (hFileMap);
            }
        }
@@ -658,6 +680,8 @@ FcDirCacheBuild (FcFontSet *set, const FcChar8 *dir, FcStrSet *dirs)
 
     FcSerializeDestroy (serialize);
     
+    FcCacheInsert (cache, NULL);
+
     return cache;
 
 bail2:
@@ -667,6 +691,11 @@ bail1:
     return NULL;
 }
 
+
+#ifdef _WIN32
+#define mkdir(path,mode) _mkdir(path)
+#endif
+
 static FcBool
 FcMakeDirectory (const FcChar8 *dir)
 {
@@ -798,16 +827,17 @@ FcDirCacheWrite (FcCache *cache, FcConfig *config)
  * Hokey little macro trick to permit the definitions of C functions
  * with the same name as CPP macros
  */
-#define args(x...)         (x)
+#define args1(x)           (x)
+#define args2(x,y)         (x,y)
 
 const FcChar8 *
-FcCacheDir args(const FcCache *c)
+FcCacheDir args1(const FcCache *c)
 {
     return FcCacheDir (c);
 }
 
 FcFontSet *
-FcCacheCopySet args(const FcCache *c)
+FcCacheCopySet args1(const FcCache *c)
 {
     FcFontSet  *old = FcCacheSet (c);
     FcFontSet  *new = FcFontSetCreate ();
@@ -830,19 +860,19 @@ FcCacheCopySet args(const FcCache *c)
 }
 
 const FcChar8 *
-FcCacheSubdir args(const FcCache *c, int i)
+FcCacheSubdir args2(const FcCache *c, int i)
 {
     return FcCacheSubdir (c, i);
 }
 
 int
-FcCacheNumSubdir args(const FcCache *c)
+FcCacheNumSubdir args1(const FcCache *c)
 {
     return c->dirs_count;
 }
 
 int
-FcCacheNumFont args(const FcCache *c)
+FcCacheNumFont args1(const FcCache *c)
 {
     return FcCacheSet(c)->nfont;
 }