]> git.wh0rd.org - fontconfig.git/commitdiff
Fix memory leaks in fc-cache directory cleaning code.
authorKeith Packard <keithp@neko.keithp.com>
Fri, 1 Sep 2006 19:07:10 +0000 (12:07 -0700)
committerKeith Packard <keithp@neko.keithp.com>
Fri, 1 Sep 2006 19:07:10 +0000 (12:07 -0700)
valgrind found a few leaks in the new cache cleaning code.

fc-cache/fc-cache.c

index 6957a65b9ba8d28b685dc12f6f94b7f3ee0c8b60..06864810446271c8da03caab9a79caeceb087fd5 100644 (file)
@@ -287,10 +287,16 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
     struct stat        target_stat;
 
     dir_base = FcStrPlus (dir, "/");
+    if (!dir_base)
+    {
+       fprintf (stderr, "%s: out of memory\n", dir);
+       return FcFalse;
+    }
     if (access ((char *) dir, W_OK|X_OK) != 0)
     {
        if (verbose)
            printf ("%s: not cleaning unwritable cache directory\n", dir);
+       FcStrFree (dir_base);
        return FcTrue;
     }
     if (verbose)
@@ -299,6 +305,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
     if (!d)
     {
        perror (dir);
+       FcStrFree (dir_base);
        return FcFalse;
     }
     while ((ent = readdir (d)))
@@ -347,10 +354,12 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
                ret = FcFalse;
            }
        }
+       FcDirCacheUnload (cache);
         FcStrFree (file_name);
     }
     
     closedir (d);
+    FcStrFree (dir_base);
     return ret;
 }