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

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
...@@ -1291,6 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, ...@@ -1291,6 +1291,7 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
0, objectid, NULL, 0, 0, 0); 0, objectid, NULL, 0, 0, 0);
if (IS_ERR(leaf)) { if (IS_ERR(leaf)) {
ret = PTR_ERR(leaf); ret = PTR_ERR(leaf);
leaf = NULL;
goto fail; goto fail;
} }
...@@ -1334,11 +1335,16 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans, ...@@ -1334,11 +1335,16 @@ struct btrfs_root *btrfs_create_tree(struct btrfs_trans_handle *trans,
btrfs_tree_unlock(leaf); btrfs_tree_unlock(leaf);
return root;
fail: fail:
if (ret) if (leaf) {
return ERR_PTR(ret); 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, static struct btrfs_root *alloc_log_tree(struct btrfs_trans_handle *trans,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment