Fix memory leaks in fc-cache directory cleaning code.

valgrind found a few leaks in the new cache cleaning code.
This commit is contained in:
Keith Packard 2006-09-01 12:07:10 -07:00
parent fd7223c770
commit 1741499e23
1 changed files with 9 additions and 0 deletions

View File

@ -287,10 +287,16 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
struct stat target_stat; struct stat target_stat;
dir_base = FcStrPlus (dir, "/"); 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 (access ((char *) dir, W_OK|X_OK) != 0)
{ {
if (verbose) if (verbose)
printf ("%s: not cleaning unwritable cache directory\n", dir); printf ("%s: not cleaning unwritable cache directory\n", dir);
FcStrFree (dir_base);
return FcTrue; return FcTrue;
} }
if (verbose) if (verbose)
@ -299,6 +305,7 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
if (!d) if (!d)
{ {
perror (dir); perror (dir);
FcStrFree (dir_base);
return FcFalse; return FcFalse;
} }
while ((ent = readdir (d))) while ((ent = readdir (d)))
@ -347,10 +354,12 @@ cleanCacheDirectory (FcConfig *config, FcChar8 *dir, FcBool verbose)
ret = FcFalse; ret = FcFalse;
} }
} }
FcDirCacheUnload (cache);
FcStrFree (file_name); FcStrFree (file_name);
} }
closedir (d); closedir (d);
FcStrFree (dir_base);
return ret; return ret;
} }