Skip to content

Commit

Permalink
Ext2: free memory allocated and forget buffer head when io error happens
Browse files Browse the repository at this point in the history
Add a necessary check when an io error happens.
If io error happens,free the memory allocated and forget
buffer head.

Signed-off-by: Wang Shilong <[email protected]>
Signed-off-by: Jan Kara <[email protected]>
  • Loading branch information
Wang Shilong authored and jankara committed Jan 21, 2013
1 parent f56426a commit 8d8759e
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions fs/ext2/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -495,6 +495,10 @@ static int ext2_alloc_branch(struct inode *inode,
* parent to disk.
*/
bh = sb_getblk(inode->i_sb, new_blocks[n-1]);
if (unlikely(!bh)) {
err = -ENOMEM;
goto failed;
}
branch[n].bh = bh;
lock_buffer(bh);
memset(bh->b_data, 0, blocksize);
Expand Down Expand Up @@ -523,6 +527,14 @@ static int ext2_alloc_branch(struct inode *inode,
}
*blks = num;
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;
}

/**
Expand Down

0 comments on commit 8d8759e

Please sign in to comment.