Commit b720303d authored by Jing Zhang's avatar Jing Zhang Committed by Theodore Ts'o

ext4: fix memory leaks in error path handling of ext4_ext_zeroout()

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: default avatarDave Kleikamp <shaggy@linux.vnet.ibm.com>
Signed-off-by: default avatarJing Zhang <zj.barak@gmail.com>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
parent c26d0bad
...@@ -2544,7 +2544,7 @@ static void bi_complete(struct bio *bio, int error) ...@@ -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 */ /* 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) static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
{ {
int ret = -EIO; int ret;
struct bio *bio; struct bio *bio;
int blkbits, blocksize; int blkbits, blocksize;
sector_t ee_pblock; sector_t ee_pblock;
...@@ -2568,6 +2568,9 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) ...@@ -2568,6 +2568,9 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
len = ee_len; len = ee_len;
bio = bio_alloc(GFP_NOIO, len); bio = bio_alloc(GFP_NOIO, len);
if (!bio)
return -ENOMEM;
bio->bi_sector = ee_pblock; bio->bi_sector = ee_pblock;
bio->bi_bdev = inode->i_sb->s_bdev; bio->bi_bdev = inode->i_sb->s_bdev;
...@@ -2595,17 +2598,15 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex) ...@@ -2595,17 +2598,15 @@ static int ext4_ext_zeroout(struct inode *inode, struct ext4_extent *ex)
submit_bio(WRITE, bio); submit_bio(WRITE, bio);
wait_for_completion(&event); wait_for_completion(&event);
if (test_bit(BIO_UPTODATE, &bio->bi_flags)) if (!test_bit(BIO_UPTODATE, &bio->bi_flags)) {
ret = 0; bio_put(bio);
else { return -EIO;
ret = -EIO;
break;
} }
bio_put(bio); bio_put(bio);
ee_len -= done; ee_len -= done;
ee_pblock += done << (blkbits - 9); ee_pblock += done << (blkbits - 9);
} }
return ret; return 0;
} }
#define EXT4_EXT_ZERO_LEN 7 #define EXT4_EXT_ZERO_LEN 7
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment