btrfs-progs: fix leak of "path" in btrfs_find_item() error paths
path needs to be freed before return. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
14ac985146
commit
380b1c8ced
20
ctree.c
20
ctree.c
|
@ -1058,26 +1058,28 @@ int btrfs_find_item(struct btrfs_root *fs_root, struct btrfs_path *found_path,
|
||||||
path = found_path;
|
path = found_path;
|
||||||
|
|
||||||
ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
|
ret = btrfs_search_slot(NULL, fs_root, &key, path, 0, 0);
|
||||||
if ((ret < 0) || (found_key == NULL)) {
|
if ((ret < 0) || (found_key == NULL))
|
||||||
if (path != found_path)
|
goto out;
|
||||||
btrfs_free_path(path);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
eb = path->nodes[0];
|
eb = path->nodes[0];
|
||||||
if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
|
if (ret && path->slots[0] >= btrfs_header_nritems(eb)) {
|
||||||
ret = btrfs_next_leaf(fs_root, path);
|
ret = btrfs_next_leaf(fs_root, path);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
goto out;
|
||||||
eb = path->nodes[0];
|
eb = path->nodes[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
btrfs_item_key_to_cpu(eb, found_key, path->slots[0]);
|
btrfs_item_key_to_cpu(eb, found_key, path->slots[0]);
|
||||||
if (found_key->type != key.type ||
|
if (found_key->type != key.type ||
|
||||||
found_key->objectid != key.objectid)
|
found_key->objectid != key.objectid) {
|
||||||
return 1;
|
ret = 1;
|
||||||
|
goto out;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
out:
|
||||||
|
if (path != found_path)
|
||||||
|
btrfs_free_path(path);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in New Issue