e2fsck: Fix leaks in error paths

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>
bitmap-optimize
Eric Sandeen 2011-09-16 15:49:36 -05:00 committed by Theodore Ts'o
parent 2bf0739dc0
commit 6d4ced2192
1 changed files with 5 additions and 2 deletions

View 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;
}
}