From: Patrick Lam Date: Wed, 25 Jan 2006 02:33:46 +0000 (+0000) Subject: Fix memory leaks reported by Ronny V. Vindenes. X-Git-Tag: fc-2_3_94~63 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=6f9fcb51861fe3066e44a23817f1c700f3475ac0;p=fontconfig.git Fix memory leaks reported by Ronny V. Vindenes. --- diff --git a/ChangeLog b/ChangeLog index 98e404c..b4c3c8a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-24 Patrick Lam + * src/fccache.c (FcDirCacheUnlink, FcDirCacheWrite): + * src/fcfreetype.c (FcFreeTypeQuery): + + Fix memory leaks reported by Ronny V. Vindenes. + 2006-01-19 Andreas Schwab reviewed by: plam diff --git a/src/fccache.c b/src/fccache.c index 10e65dd..688da87 100644 --- a/src/fccache.c +++ b/src/fccache.c @@ -658,7 +658,7 @@ FcBool FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) { char *cache_file; - char *cache_hashed; + char *cache_hashed = 0; int fd, collisions; struct stat cache_stat; char name_buf[FC_MAX_FILE_LEN]; @@ -677,6 +677,9 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) fd = -1; collisions = 0; do { + if (cache_hashed) + FcStrFree ((FcChar8 *)cache_hashed); + cache_hashed = FcDirCacheHashName (cache_file, collisions++); if (!cache_hashed) goto bail; @@ -692,7 +695,10 @@ FcDirCacheUnlink (const FcChar8 *dir, FcConfig *config) FcCacheReadString (fd, name_buf, sizeof (name_buf)); if (!strlen(name_buf)) + { + FcStrFree ((FcChar8 *)cache_hashed); goto bail; + } } while (strcmp (name_buf, cache_file) != 0); FcStrFree ((FcChar8 *)cache_file); @@ -1189,6 +1195,7 @@ FcDirCacheWrite (FcFontSet *set, FcStrSet *dirs, const FcChar8 *dir) if (ftruncate (fd, current_arch_start + truncate_to) == -1) goto bail5; + free (header); close(fd); if (!FcAtomicReplaceOrig(atomic)) goto bail5; diff --git a/src/fcfreetype.c b/src/fcfreetype.c index 0b976f7..7f0af31 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -1000,6 +1000,7 @@ FcFreeTypeQuery (const FcChar8 *file, FcChar8 *family = 0; #endif FcChar8 *complex; + FcChar8 *file2; const FcChar8 *foundry = 0; int spacing; TT_OS2 *os2; @@ -1280,8 +1281,13 @@ FcFreeTypeQuery (const FcChar8 *file, printf ("Saving unique fullname %s\n", full); } - if (!FcPatternAddString (pat, FC_FILE, (FcChar8 *)basename((char *)FcStrCopy(file)))) + file2 = FcStrCopy (file); + if (!FcPatternAddString (pat, FC_FILE, (FcChar8 *)basename((char *)file2))) + { + FcStrFree (file2); goto bail1; + } + FcStrFree (file2); FcPatternAddFullFname (pat, (const char *)FcStrCopy (file));