Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3321719e authored by Liu Bo's avatar Liu Bo Committed by Josef Bacik
Browse files

Btrfs: fix memory leak of log roots



When we abort a transaction while fsyncing, we'll skip freeing log roots
part of committing a transaction, which leads to memory leak.

This adds a 'free log roots' in putting super when no more users hold
references on log roots, so it's safe and clean.

Signed-off-by: default avatarLiu Bo <bo.li.liu@oracle.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
parent bdc20e67
Loading
Loading
Loading
Loading
+5 −0
Original line number Original line Diff line number Diff line
@@ -3253,6 +3253,11 @@ void btrfs_free_fs_root(struct btrfs_fs_info *fs_info, struct btrfs_root *root)
	if (btrfs_root_refs(&root->root_item) == 0)
	if (btrfs_root_refs(&root->root_item) == 0)
		synchronize_srcu(&fs_info->subvol_srcu);
		synchronize_srcu(&fs_info->subvol_srcu);


	if (fs_info->fs_state & BTRFS_SUPER_FLAG_ERROR) {
		btrfs_free_log(NULL, root);
		btrfs_free_log_root_tree(NULL, fs_info);
	}

	__btrfs_remove_free_space_cache(root->free_ino_pinned);
	__btrfs_remove_free_space_cache(root->free_ino_pinned);
	__btrfs_remove_free_space_cache(root->free_ino_ctl);
	__btrfs_remove_free_space_cache(root->free_ino_ctl);
	free_fs_root(root);
	free_fs_root(root);
+4 −2
Original line number Original line Diff line number Diff line
@@ -2466,8 +2466,10 @@ static void free_log_tree(struct btrfs_trans_handle *trans,
		.process_func = process_one_buffer
		.process_func = process_one_buffer
	};
	};


	if (trans) {
		ret = walk_log_tree(trans, log, &wc);
		ret = walk_log_tree(trans, log, &wc);
		BUG_ON(ret);
		BUG_ON(ret);
	}


	while (1) {
	while (1) {
		ret = find_first_extent_bit(&log->dirty_log_pages,
		ret = find_first_extent_bit(&log->dirty_log_pages,