aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorZixuan Fu <[email protected]>2022-08-15 23:16:06 +0800
committerDavid Sterba <[email protected]>2022-08-22 18:06:33 +0200
commit9ea0106a7a3d8116860712e3f17cd52ce99f6707 (patch)
tree84332b7037a6dd5c9173260f35c7abcd2e69d5c3
parentb51111271b0352aa596c5ae8faf06939e91b3b68 (diff)
btrfs: fix possible memory leak in btrfs_get_dev_args_from_path()
In btrfs_get_dev_args_from_path(), btrfs_get_bdev_and_sb() can fail if the path is invalid. In this case, btrfs_get_dev_args_from_path() returns directly without freeing args->uuid and args->fsid allocated before, which causes memory leak. To fix these possible leaks, when btrfs_get_bdev_and_sb() fails, btrfs_put_dev_args_from_path() is called to clean up the memory. Reported-by: TOTE Robot <[email protected]> Fixes: faa775c41d655 ("btrfs: add a btrfs_get_dev_args_from_path helper") CC: [email protected] # 5.16 Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Zixuan Fu <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]>
-rw-r--r--fs/btrfs/volumes.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 272901514b0c..064ab2a79c80 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -2345,8 +2345,11 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
ret = btrfs_get_bdev_and_sb(path, FMODE_READ, fs_info->bdev_holder, 0,
&bdev, &disk_super);
- if (ret)
+ if (ret) {
+ btrfs_put_dev_args_from_path(args);
return ret;
+ }
+
args->devid = btrfs_stack_device_id(&disk_super->dev_item);
memcpy(args->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE);
if (btrfs_fs_incompat(fs_info, METADATA_UUID))