[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 <behlendorf1@llnl.gov>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
bitmap-optimize
Brian Behlendorf 2007-03-21 16:14:37 -04:00 committed by Theodore Ts'o
parent b772900b4b
commit 93503267c9
2 changed files with 8 additions and 1 deletions

View File

@ -1,3 +1,8 @@
2007-03-21 Theodore Tso <tytso@mit.edu>
* profile.c (profile_open_file): Fix memory leak if malloc() fails
while setting up the profile data structure.
2007-03-19 Theodore Tso <tytso@mit.edu>
* pass3.c (check_directory): Add error check in case

View File

@ -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);