diff options
author | David Sterba <dsterba@suse.cz> | 2015-01-02 18:45:16 +0100 |
---|---|---|
committer | David Sterba <dsterba@suse.cz> | 2015-01-14 19:23:46 +0100 |
commit | 381cf6587f8a8a8e981bc0c1aaaa8859b51dc756 (patch) | |
tree | 024b49bf7f036ff79846076c44710337bd0d5ec1 /fs/btrfs/disk-io.c | |
parent | eaa27f34e91a14cdceed26ed6c6793ec1d186115 (diff) | |
download | lwn-381cf6587f8a8a8e981bc0c1aaaa8859b51dc756.tar.gz lwn-381cf6587f8a8a8e981bc0c1aaaa8859b51dc756.zip |
btrfs: fix leak of path in btrfs_find_item
If btrfs_find_item is called with NULL path it allocates one locally but
does not free it. Affected paths are inserting an orphan item for a file
and for a subvol root.
Move the path allocation to the callers.
CC: <stable@vger.kernel.org> # 3.14+
Fixes: 3f870c289900 ("btrfs: expand btrfs_find_item() to include find_orphan_item functionality")
Signed-off-by: David Sterba <dsterba@suse.cz>
Diffstat (limited to 'fs/btrfs/disk-io.c')
-rw-r--r-- | fs/btrfs/disk-io.c | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 8c63419a7f70..6182e5493d0f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -1630,6 +1630,7 @@ struct btrfs_root *btrfs_get_fs_root(struct btrfs_fs_info *fs_info, bool check_ref) { struct btrfs_root *root; + struct btrfs_path *path; int ret; if (location->objectid == BTRFS_ROOT_TREE_OBJECTID) @@ -1669,8 +1670,14 @@ again: if (ret) goto fail; - ret = btrfs_find_item(fs_info->tree_root, NULL, BTRFS_ORPHAN_OBJECTID, + path = btrfs_alloc_path(); + if (!path) { + ret = -ENOMEM; + goto fail; + } + ret = btrfs_find_item(fs_info->tree_root, path, BTRFS_ORPHAN_OBJECTID, location->objectid, BTRFS_ORPHAN_ITEM_KEY, NULL); + btrfs_free_path(path); if (ret < 0) goto fail; if (ret == 0) |