diff mbox

[18/25] e2initrd_helper: Fix memory leak on error

Message ID 1316206180-6375-19-git-send-email-sandeen@redhat.com
State Accepted, archived
Headers show

Commit Message

Eric Sandeen Sept. 16, 2011, 8:49 p.m. UTC
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>
---
 misc/e2initrd_helper.c |   11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

Comments

Theodore Ts'o Sept. 16, 2011, 10:58 p.m. UTC | #1
On Fri, Sep 16, 2011 at 03:49:33PM -0500, Eric Sandeen wrote:
> 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>

Applied, thanks.

					- Ted
--
To unsubscribe from this list: send the line "unsubscribe linux-ext4" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/misc/e2initrd_helper.c b/misc/e2initrd_helper.c
index eaf9ce6..3d9f5ab 100644
--- a/misc/e2initrd_helper.c
+++ b/misc/e2initrd_helper.c
@@ -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;
 }