Skip to content

Commit

Permalink
ext4: fix memory leaks in error path handling of ext4_ext_zeroout()
Browse files Browse the repository at this point in the history
When EIO occurs after bio is submitted, there is no memory free
operation for bio, which results in memory leakage. And there is also
no check against bio_alloc() for bio.

Acked-by: Dave Kleikamp <shaggy@linux.vnet.ibm.com>
Signed-off-by: Jing Zhang <zj.barak@gmail.com>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
  • Loading branch information
Jing Zhang authored and Theodore Ts'o committed May 12, 2010
1 parent c26d0ba commit b720303
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions fs/ext4/extents.c
Original file line number Diff line number Diff line change
Expand Up @@ -2544,7 +2544,7 @@ static void bi_complete(struct bio *bio, int error)
/* FIXME!! we need to try to merge to left or right after zero-out */
static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
{
int ret = -EIO;
int ret;
struct bio *bio;
int blkbits, blocksize;
sector_t ee_pblock;
Expand All @@ -2568,6 +2568,9 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
len = ee_len;

bio = bio_alloc(GFP_NOIO, len);
if (!bio)
return -ENOMEM;

bio->bi_sector = ee_pblock;
bio->bi_bdev = inode->i_sb->s_bdev;

Expand Down Expand Up @@ -2595,17 +2598,15 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
submit_bio(WRITE, bio);
wait_for_completion(&event);

if (test_bit(BIO_UPTODATE, &bio->bi_flags))
ret = 0;
else {
ret = -EIO;
break;
if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
bio_put(bio);
return -EIO;
}
bio_put(bio);
ee_len -= done;
ee_pblock += done << (blkbits - 9);
}
return ret;
return 0;
}

#define EXT4_EXT_ZERO_LEN 7
Expand Down

0 comments on commit b720303

Please sign in to comment.