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

Commit 1dd05682 authored by Tsutomu Itoh's avatar Tsutomu Itoh Committed by Chris Mason
Browse files

Btrfs: fix memory leak in btrfs_create_tree()



We should free leaf and root before returning from the error
handling code.

Signed-off-by: default avatarTsutomu Itoh <t-itoh@jp.fujitsu.com>
Signed-off-by: default avatarJosef Bacik <jbacik@fusionio.com>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent d9abbf1c
Loading
Loading
Loading
Loading
+9 −3
Original line number Diff line number Diff line
@@ -1291,6 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
				      0, objectid, NULL, 0, 0, 0);
	if (IS_ERR(leaf)) {
		ret = PTR_ERR(leaf);
		leaf = NULL;
		goto fail;
	}

@@ -1334,11 +1335,16 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,

	btrfs_tree_unlock(leaf);

	return root;

fail:
	if (ret)
		return ERR_PTR(ret);
	if (leaf) {
		btrfs_tree_unlock(leaf);
		free_extent_buffer(leaf);
	}
	kfree(root);

	return root;
	return ERR_PTR(ret);
}

static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,