Skip to content

Commit 4f26433

Browse files
fdmananakdave
authored andcommitted
btrfs: fix memory leaks after failure to lookup checksums during inode logging
While logging an inode, at copy_items(), if we fail to lookup the checksums for an extent we release the destination path, free the ins_data array and then return immediately. However a previous iteration of the for loop may have added checksums to the ordered_sums list, in which case we leak the memory used by them. So fix this by making sure we iterate the ordered_sums list and free all its checksums before returning. Fixes: 3650860 ("Btrfs: remove almost all of the BUG()'s from tree-log.c") CC: [email protected] # 4.4+ Reviewed-by: Johannes Thumshirn <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 3ef3959 commit 4f26433

File tree

1 file changed

+2
-6
lines changed

1 file changed

+2
-6
lines changed

fs/btrfs/tree-log.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4036,11 +4036,8 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
40364036
fs_info->csum_root,
40374037
ds + cs, ds + cs + cl - 1,
40384038
&ordered_sums, 0);
4039-
if (ret) {
4040-
btrfs_release_path(dst_path);
4041-
kfree(ins_data);
4042-
return ret;
4043-
}
4039+
if (ret)
4040+
break;
40444041
}
40454042
}
40464043
}
@@ -4053,7 +4050,6 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
40534050
* we have to do this after the loop above to avoid changing the
40544051
* log tree while trying to change the log tree.
40554052
*/
4056-
ret = 0;
40574053
while (!list_empty(&ordered_sums)) {
40584054
struct btrfs_ordered_sum *sums = list_entry(ordered_sums.next,
40594055
struct btrfs_ordered_sum,

0 commit comments

Comments
 (0)