]> git.ipfire.org Git - thirdparty/e2fsprogs.git/commitdiff
libext2fs: fix some memory leaks with image file handling
authorTheodore Ts'o <tytso@mit.edu>
Mon, 2 Dec 2013 19:52:31 +0000 (14:52 -0500)
committerTheodore Ts'o <tytso@mit.edu>
Mon, 2 Dec 2013 19:52:31 +0000 (14:52 -0500)
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
lib/ext2fs/openfs.c

index 28c4132fd9d9d1177be7c8ce40b28dd27f07c5a8..1ad2d916f490c931c76b1da42e266480b994adf0 100644 (file)
@@ -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);
index c38b586395d9b55a4e9eaa01b6fb50ea106209cf..4cdbde16d9bae1b0a92b9a1ad21cb68c124755cc 100644 (file)
@@ -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;