From: Theodore Ts'o <tytso@mit.edu>
To: Ext4 Developers List <linux-ext4@vger.kernel.org>
Cc: kwestneat@ddn.com, Theodore Ts'o <tytso@mit.edu>
Subject: [PATCH 3/3] libext2fs: fix some memory leaks with image file handling
Date: Mon, 2 Dec 2013 14:55:25 -0500 [thread overview]
Message-ID: <1386014125-13664-3-git-send-email-tytso@mit.edu> (raw)
In-Reply-To: <1386014125-13664-1-git-send-email-tytso@mit.edu>
These memory leaks were discovered by using "valgrind
--leak-check=full" while running "e2image -I bar.img foo.e2i"
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
---
lib/ext2fs/freefs.c | 2 ++
lib/ext2fs/openfs.c | 7 +++++++
2 files changed, 9 insertions(+)
diff --git a/lib/ext2fs/freefs.c b/lib/ext2fs/freefs.c
index 28c4132..1ad2d91 100644
--- a/lib/ext2fs/freefs.c
+++ b/lib/ext2fs/freefs.c
@@ -43,6 +43,8 @@ void ext2fs_free(ext2_filsys fs)
ext2fs_free_block_bitmap(fs->block_map);
if (fs->inode_map)
ext2fs_free_inode_bitmap(fs->inode_map);
+ if (fs->image_header)
+ ext2fs_free_mem(&fs->image_header);
if (fs->badblocks)
ext2fs_badblocks_list_free(fs->badblocks);
diff --git a/lib/ext2fs/openfs.c b/lib/ext2fs/openfs.c
index c38b586..4cdbde1 100644
--- a/lib/ext2fs/openfs.c
+++ b/lib/ext2fs/openfs.c
@@ -458,6 +458,13 @@ errcode_t ext2fs_rewrite_to_io(ext2_filsys fs, io_channel new_io)
err = io_channel_set_blksize(new_io, fs->blocksize);
if (err)
return err;
+ if ((new_io == fs->image_io) || (new_io == fs->io))
+ return 0;
+ if ((fs->image_io != fs->io) &&
+ fs->image_io)
+ io_channel_close(fs->image_io);
+ if (fs->io)
+ io_channel_close(fs->io);
fs->io = fs->image_io = new_io;
fs->flags |= EXT2_FLAG_DIRTY | EXT2_FLAG_RW |
EXT2_FLAG_BB_DIRTY | EXT2_FLAG_IB_DIRTY;
--
1.8.5.rc3.362.gdf10213
next prev parent reply other threads:[~2013-12-02 19:55 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-11-27 21:32 [PATCH] e2image: double free when restoring image Kit Westneat
2013-11-29 17:45 ` Dilger, Andreas
2013-12-02 17:27 ` Kit Westneat
2013-12-02 18:26 ` Theodore Ts'o
2013-12-02 19:55 ` [PATCH 1/3] e2image: pass the correct size write_header Theodore Ts'o
2013-12-02 19:55 ` [PATCH 2/3] libext2fs: set the fs block size to new_io in ext2fs_rewrite_to_io() Theodore Ts'o
2013-12-02 19:55 ` Theodore Ts'o [this message]
2013-12-02 18:03 ` [PATCH] e2image: double free when restoring image Theodore Ts'o
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1386014125-13664-3-git-send-email-tytso@mit.edu \
--to=tytso@mit.edu \
--cc=kwestneat@ddn.com \
--cc=linux-ext4@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).