Skip to content

Commit 9ea0106

Browse files
r33s3n6kdave
authored andcommitted
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: faa775c ("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]>
1 parent b511112 commit 9ea0106

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2345,8 +2345,11 @@ int btrfs_get_dev_args_from_path(struct btrfs_fs_info *fs_info,
23452345

23462346
ret = btrfs_get_bdev_and_sb(path, FMODE_READ, fs_info->bdev_holder, 0,
23472347
&bdev, &disk_super);
2348-
if (ret)
2348+
if (ret) {
2349+
btrfs_put_dev_args_from_path(args);
23492350
return ret;
2351+
}
2352+
23502353
args->devid = btrfs_stack_device_id(&disk_super->dev_item);
23512354
memcpy(args->uuid, disk_super->dev_item.uuid, BTRFS_UUID_SIZE);
23522355
if (btrfs_fs_incompat(fs_info, METADATA_UUID))

0 commit comments

Comments
 (0)