From 93503267c9765f80f8bbbdbb132d495a859361e1 Mon Sep 17 00:00:00 2001 From: Brian Behlendorf Date: Wed, 21 Mar 2007 16:14:37 -0400 Subject: [PATCH] [COVERITY] Fix memory leak in profile library The profile must be freed early if the subsequent memory allocation fails for 'expanded_filename'. Coverity ID: 14: Resource Leak Signed-off-by: Brian Behlendorf Signed-off-by: "Theodore Ts'o" --- e2fsck/ChangeLog | 5 +++++ e2fsck/profile.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 4e0ba889..8d5e491c 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,3 +1,8 @@ +2007-03-21 Theodore Tso + + * profile.c (profile_open_file): Fix memory leak if malloc() fails + while setting up the profile data structure. + 2007-03-19 Theodore Tso * pass3.c (check_directory): Add error check in case diff --git a/e2fsck/profile.c b/e2fsck/profile.c index 8030680b..3352a221 100644 --- a/e2fsck/profile.c +++ b/e2fsck/profile.c @@ -417,8 +417,10 @@ errcode_t profile_open_file(const char * filespec, len += strlen(home_env); } expanded_filename = malloc(len); - if (expanded_filename == 0) + if (expanded_filename == 0) { + profile_free_file(prf); return errno; + } if (home_env) { strcpy(expanded_filename, home_env); strcat(expanded_filename, filespec+1);