e2initrd_helper: Fix memory leak on error

Some error paths did not properly free "buf"

And the normal exit seemed to close e2_file twice (?)

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:33 -05:00 committed by Theodore Ts'o
parent 9f7c3afaef
commit 7adf589249
1 changed files with 7 additions and 4 deletions

View File

@ -73,7 +73,7 @@ static errcode_t get_file(ext2_filsys fs, const char * filename,
{
errcode_t retval;
char *buf;
ext2_file_t e2_file;
ext2_file_t e2_file = NULL;
unsigned int got;
struct ext2_inode inode;
ext2_ino_t ino;
@ -101,7 +101,7 @@ static errcode_t get_file(ext2_filsys fs, const char * filename,
retval = ext2fs_file_open(fs, ino, 0, &e2_file);
if (retval)
return retval;
goto errout;
retval = ext2fs_file_read(e2_file, buf, inode.i_size, &got);
if (retval)
@ -109,13 +109,16 @@ static errcode_t get_file(ext2_filsys fs, const char * filename,
retval = ext2fs_file_close(e2_file);
if (retval)
return retval;
goto errout;
ret_file->buf = buf;
ret_file->size = (int) got;
return 0;
errout:
ext2fs_file_close(e2_file);
free(buf);
if (e2_file)
ext2fs_file_close(e2_file);
return retval;
}