]> git.wh0rd.org Git - fontconfig.git/commitdiff
src/fcdir.c (FcDirScanConfig) Don't leak in error cases (Coverity defects
authorPatrick Lam <plam@MIT.EDU>
Mon, 10 Apr 2006 16:06:42 +0000 (16:06 +0000)
committerPatrick Lam <plam@MIT.EDU>
Mon, 10 Apr 2006 16:06:42 +0000 (16:06 +0000)
    #777, #1826)
reviewed by: plam

ChangeLog
src/fcdir.c

index c999df4413a9c10d223c17d442bfe55c6ec54959..6d1a348f576ef952cc5ae862bc11284ef2b84e40 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2006-04-10  Frederic Crozat  <fcrozat@mandriva.com>
+       reviewed by: plam
+
+       * src/fcdir.c (FcDirScanConfig)
+       Don't leak in error cases (Coverity defects #777, #1826)
+
 2006-04-10  Frederic Crozat  <fcrozat@mandriva.com>
        reviewed by: plam
 
index f505bf533b3396641c25296589a6d2cb3de0b92d..4463b3130cceba58000af27378d3708b2c3853e8 100644 (file)
@@ -180,31 +180,44 @@ FcDirScanConfig (FcFontSet        *set,
     }
 
     tmpSet = FcFontSetCreate();
-    if (!tmpSet)
-    {  
-       free (file);
-       return FcFalse;
+    if (!tmpSet) 
+    {
+       ret = FcFalse;
+       goto bail0;
     }
 
     dirlistlen = 0;
     dirlistalloc = 8;
     dirlist = malloc(dirlistalloc * sizeof(FcChar8 *));
-    if (!dirlist)
-       return FcFalse;
+    if (!dirlist) 
+    {
+       ret = FcFalse;
+       goto bail1;
+    }
     while ((e = readdir (d)))
     {
        if (e->d_name[0] != '.' && strlen (e->d_name) < FC_MAX_FILE_LEN)
        {
            if (dirlistlen == dirlistalloc)
            {
+                FcChar8        **tmp_dirlist;
+
                dirlistalloc *= 2;
-               dirlist = realloc(dirlist, dirlistalloc * sizeof(FcChar8 *));
-               if (!dirlist)
-                   return FcFalse;
+               tmp_dirlist = realloc(dirlist, 
+                                      dirlistalloc * sizeof(FcChar8 *));
+               if (!tmp_dirlist) 
+                {
+                   ret = FcFalse;
+                   goto bail2;
+               }
+                dirlist = tmp_dirlist;
            }
            dirlist[dirlistlen] = malloc(strlen (e->d_name) + 1);
-           if (!dirlist[dirlistlen])
-               return FcFalse;
+           if (!dirlist[dirlistlen]) 
+            {
+               ret = FcFalse;
+               goto bail2;
+           }
            strcpy((char *)dirlist[dirlistlen], e->d_name);
            dirlistlen++;
        }
@@ -217,11 +230,6 @@ FcDirScanConfig (FcFontSet *set,
        ret = FcFileScanConfig (tmpSet, dirs, cache, blanks, file, force, config);
        i++;
     }
-    for (i = 0; i < dirlistlen; i++)
-       free(dirlist[i]);
-    free (dirlist);
-    free (file);
-    closedir (d);
     /*
      * Now that the directory has been scanned,
      * add the cache entry 
@@ -238,8 +246,20 @@ FcDirScanConfig (FcFontSet *set,
        free (tmpSet->fonts);
     }
     FcMemFree (FC_MEM_FONTSET, sizeof (FcFontSet));
+
+ bail2:
+    for (i = 0; i < dirlistlen; i++)
+       free(dirlist[i]);
+
+    free (dirlist);
+
+ bail1:
     free (tmpSet);
-       
+    
+ bail0:
+    closedir (d);
+    
+    free (file);
     return ret;
 }