Skip to content

Commit 183af2d

Browse files
fdmananagregkh
authored andcommitted
btrfs: fix memory leaks after failure to lookup checksums during inode logging
commit 4f26433 upstream. 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: stable@vger.kernel.org # 4.4+ Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 627fa9d commit 183af2d

1 file changed

Lines changed: 2 additions & 6 deletions

File tree

fs/btrfs/tree-log.c

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3988,11 +3988,8 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
39883988
fs_info->csum_root,
39893989
ds + cs, ds + cs + cl - 1,
39903990
&ordered_sums, 0);
3991-
if (ret) {
3992-
btrfs_release_path(dst_path);
3993-
kfree(ins_data);
3994-
return ret;
3995-
}
3991+
if (ret)
3992+
break;
39963993
}
39973994
}
39983995
}
@@ -4005,7 +4002,6 @@ static noinline int copy_items(struct btrfs_trans_handle *trans,
40054002
* we have to do this after the loop above to avoid changing the
40064003
* log tree while trying to change the log tree.
40074004
*/
4008-
ret = 0;
40094005
while (!list_empty(&ordered_sums)) {
40104006
struct btrfs_ordered_sum *sums = list_entry(ordered_sums.next,
40114007
struct btrfs_ordered_sum,

0 commit comments

Comments
 (0)