Whamcloud - gitweb
e2fsck: Fix leaks in error paths
authorEric Sandeen <sandeen@redhat.com>
Fri, 16 Sep 2011 20:49:36 +0000 (15:49 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Fri, 16 Sep 2011 23:55:55 +0000 (19:55 -0400)
fn and/or array was not freed in some error paths.

[ Also make sure the array is NULL terminated before we free it in
  get_dirlist(). --tytso]

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
e2fsck/profile.c

index 327bfb4..f4267b1 100644 (file)
@@ -276,6 +276,7 @@ static errcode_t get_dirlist(const char *dirname, char***ret_array)
                        new_array = realloc(array, sizeof(char *) * (max+1));
                        if (!new_array) {
                                retval = ENOMEM;
+                               free(fn);
                                goto errout;
                        }
                        array = new_array;
@@ -290,6 +291,8 @@ static errcode_t get_dirlist(const char *dirname, char***ret_array)
        closedir(dir);
        return 0;
 errout:
+       if (array)
+               array[num] = 0;
        closedir(dir);
        free_list(array);
        return retval;
@@ -345,8 +348,8 @@ profile_init(const char **files, profile_t *ret_profile)
             * If all the files were not found, return the appropriate error.
             */
            if (!profile->first_file) {
-               profile_release(profile);
-               return ENOENT;
+               retval = ENOENT;
+               goto errout;
            }
        }