2022-04-22 21:43:55

by baihaowen

[permalink] [raw]
Subject: [PATCH] btrfs: Fix a memory leak in btrfs_ioctl_balance()

Free "bargs" before return.

Signed-off-by: Haowen Bai <[email protected]>
---
fs/btrfs/ioctl.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
index f08233c2b0b2..d4c8bea914b7 100644
--- a/fs/btrfs/ioctl.c
+++ b/fs/btrfs/ioctl.c
@@ -4389,13 +4389,13 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
/* this is (2) */
mutex_unlock(&fs_info->balance_mutex);
ret = -EINPROGRESS;
- goto out;
+ goto out_bargs;
}
} else {
/* this is (1) */
mutex_unlock(&fs_info->balance_mutex);
ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
- goto out;
+ goto out_bargs;
}

locked:
--
2.7.4


2022-04-22 22:32:46

by Qu Wenruo

[permalink] [raw]
Subject: Re: [PATCH] btrfs: Fix a memory leak in btrfs_ioctl_balance()



On 2022/4/21 17:51, Haowen Bai wrote:
> Free "bargs" before return.
>
> Signed-off-by: Haowen Bai <[email protected]>
> ---
> fs/btrfs/ioctl.c | 4 ++--
> 1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
> index f08233c2b0b2..d4c8bea914b7 100644
> --- a/fs/btrfs/ioctl.c
> +++ b/fs/btrfs/ioctl.c
> @@ -4389,13 +4389,13 @@ static long btrfs_ioctl_balance(struct file *file, void __user *arg)
> /* this is (2) */
> mutex_unlock(&fs_info->balance_mutex);
> ret = -EINPROGRESS;
> - goto out;
> + goto out_bargs;
> }
> } else {
> /* this is (1) */
> mutex_unlock(&fs_info->balance_mutex);
> ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS;
> - goto out;
> + goto out_bargs;

out_bargs will also unlock balance mutex, causing a double unlock.


> }
>
> locked:

2022-04-22 23:01:52

by David Sterba

[permalink] [raw]
Subject: Re: [PATCH] btrfs: Fix a memory leak in btrfs_ioctl_balance()

On Thu, Apr 21, 2022 at 05:51:17PM +0800, Haowen Bai wrote:
> Free "bargs" before return.
>
> Signed-off-by: Haowen Bai <[email protected]>

Thanks for the report, as the leak was in a staged patch it can be fixed
in place, which I did by applying a fixup from Nikolay.