Commit 8d8759eb authored by Wang Shilong's avatar Wang Shilong Committed by Jan Kara

Ext2: free memory allocated and forget buffer head when io error happens

Add a necessary check when an io error happens.
If io error happens,free the memory allocated and forget
buffer head.
Signed-off-by: default avatarWang Shilong <wangsl-fnst@cn.fujitsu.com>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
parent f56426ae
...@@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode, ...@@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode,
* parent to disk. * parent to disk.
*/ */
bh = sb_getblk(inode->i_sb, new_blocks[n-1]); bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
if (unlikely(!bh)) {
err = -ENOMEM;
goto failed;
}
branch[n].bh = bh; branch[n].bh = bh;
lock_buffer(bh); lock_buffer(bh);
memset(bh->b_data, 0, blocksize); memset(bh->b_data, 0, blocksize);
...@@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode, ...@@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode,
} }
*blks = num; *blks = num;
return err; return err;
failed:
for (i = 1; i < n; i++)
bforget(branch[i].bh);
for (i = 0; i < indirect_blks; i++)
ext2_free_blocks(inode, new_blocks[i], 1);
ext2_free_blocks(inode, new_blocks[i], num);
return err;
} }
/** /**
......
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