[COVERITY] Fix (error case only) memory leak in e2fsck -S

Coverity ID: 41: 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-28 12:36:41 -04:00 committed by Theodore Ts'o
parent 49e2df2954
commit 1db4c4397d
2 changed files with 12 additions and 8 deletions

View File

@ -1,7 +1,8 @@
2007-03-28 Theodore Tso <tytso@mit.edu> 2007-03-28 Theodore Tso <tytso@mit.edu>
* pass1.c (e2fsck_pass1, check_ext_attr), * pass1.c (e2fsck_pass1, check_ext_attr),
pass5.c (check_block_bitmaps, check_inode_bitmaps): pass5.c (check_block_bitmaps, check_inode_bitmaps),
swapfs.c (swap_inodes),
unix.c (parse_extended_opts): Fix memory leaks unix.c (parse_extended_opts): Fix memory leaks
2007-03-21 Theodore Tso <tytso@mit.edu> 2007-03-21 Theodore Tso <tytso@mit.edu>

View File

@ -113,7 +113,7 @@ static void swap_inodes(e2fsck_t ctx)
dgrp_t group; dgrp_t group;
unsigned int i; unsigned int i;
ext2_ino_t ino = 1; ext2_ino_t ino = 1;
char *buf, *block_buf; char *buf = NULL, *block_buf = NULL;
errcode_t retval; errcode_t retval;
struct ext2_inode * inode; struct ext2_inode * inode;
@ -125,7 +125,7 @@ static void swap_inodes(e2fsck_t ctx)
com_err("swap_inodes", retval, com_err("swap_inodes", retval,
_("while allocating inode buffer")); _("while allocating inode buffer"));
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; goto errout;
} }
block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 4, block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 4,
"block interate buffer"); "block interate buffer");
@ -138,7 +138,7 @@ static void swap_inodes(e2fsck_t ctx)
_("while reading inode table (group %d)"), _("while reading inode table (group %d)"),
group); group);
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; goto errout;
} }
inode = (struct ext2_inode *) buf; inode = (struct ext2_inode *) buf;
for (i=0; i < fs->super->s_inodes_per_group; for (i=0; i < fs->super->s_inodes_per_group;
@ -163,7 +163,7 @@ static void swap_inodes(e2fsck_t ctx)
swap_inode_blocks(ctx, ino, block_buf, inode); swap_inode_blocks(ctx, ino, block_buf, inode);
if (ctx->flags & E2F_FLAG_SIGNAL_MASK) if (ctx->flags & E2F_FLAG_SIGNAL_MASK)
return; goto errout;
if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE) if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE)
ext2fs_swap_inode(fs, inode, inode, 1); ext2fs_swap_inode(fs, inode, inode, 1);
@ -176,11 +176,14 @@ static void swap_inodes(e2fsck_t ctx)
_("while writing inode table (group %d)"), _("while writing inode table (group %d)"),
group); group);
ctx->flags |= E2F_FLAG_ABORT; ctx->flags |= E2F_FLAG_ABORT;
return; goto errout;
} }
} }
ext2fs_free_mem(&buf); errout:
ext2fs_free_mem(&block_buf); if (buf)
ext2fs_free_mem(&buf);
if (block_buf)
ext2fs_free_mem(&block_buf);
e2fsck_use_inode_shortcuts(ctx, 0); e2fsck_use_inode_shortcuts(ctx, 0);
ext2fs_flush_icache(fs); ext2fs_flush_icache(fs);
} }