From: Brian Behlendorf Date: Wed, 28 Mar 2007 16:36:41 +0000 (-0400) Subject: [COVERITY] Fix (error case only) memory leak in e2fsck -S X-Git-Tag: E2FSPROGS-1_40~87 X-Git-Url: https://git.whamcloud.com/?a=commitdiff_plain;h=1db4c4397df4918514c750a70e543fb0f865bc54;p=tools%2Fe2fsprogs.git [COVERITY] Fix (error case only) memory leak in e2fsck -S Coverity ID: 41: Resource Leak Signed-off-by: Brian Behlendorf Signed-off-by: "Theodore Ts'o" --- diff --git a/e2fsck/ChangeLog b/e2fsck/ChangeLog index 84b0ddc..2bde52b 100644 --- a/e2fsck/ChangeLog +++ b/e2fsck/ChangeLog @@ -1,7 +1,8 @@ 2007-03-28 Theodore Tso * 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 2007-03-21 Theodore Tso diff --git a/e2fsck/swapfs.c b/e2fsck/swapfs.c index 8d46404..fb7270c 100644 --- a/e2fsck/swapfs.c +++ b/e2fsck/swapfs.c @@ -113,7 +113,7 @@ static void swap_inodes(e2fsck_t ctx) dgrp_t group; unsigned int i; ext2_ino_t ino = 1; - char *buf, *block_buf; + char *buf = NULL, *block_buf = NULL; errcode_t retval; struct ext2_inode * inode; @@ -125,7 +125,7 @@ static void swap_inodes(e2fsck_t ctx) com_err("swap_inodes", retval, _("while allocating inode buffer")); ctx->flags |= E2F_FLAG_ABORT; - return; + goto errout; } block_buf = (char *) e2fsck_allocate_memory(ctx, fs->blocksize * 4, "block interate buffer"); @@ -138,7 +138,7 @@ static void swap_inodes(e2fsck_t ctx) _("while reading inode table (group %d)"), group); ctx->flags |= E2F_FLAG_ABORT; - return; + goto errout; } inode = (struct ext2_inode *) buf; 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); if (ctx->flags & E2F_FLAG_SIGNAL_MASK) - return; + goto errout; if (fs->flags & EXT2_FLAG_SWAP_BYTES_WRITE) ext2fs_swap_inode(fs, inode, inode, 1); @@ -176,11 +176,14 @@ static void swap_inodes(e2fsck_t ctx) _("while writing inode table (group %d)"), group); ctx->flags |= E2F_FLAG_ABORT; - return; + goto errout; } } - ext2fs_free_mem(&buf); - ext2fs_free_mem(&block_buf); +errout: + if (buf) + ext2fs_free_mem(&buf); + if (block_buf) + ext2fs_free_mem(&block_buf); e2fsck_use_inode_shortcuts(ctx, 0); ext2fs_flush_icache(fs); }