From 6d4ced2192766f09f021ed801797961ad2f8e258 Mon Sep 17 00:00:00 2001 From: Eric Sandeen Date: Fri, 16 Sep 2011 15:49:36 -0500 Subject: [PATCH] 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 Signed-off-by: Theodore Ts'o --- e2fsck/profile.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/e2fsck/profile.c b/e2fsck/profile.c index 327bfb48..f4267b14 100644 --- a/e2fsck/profile.c +++ b/e2fsck/profile.c @@ -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; } }