2021-11-17 07:57:45

by 赵军奎

[permalink] [raw]
Subject: 答复: [PATCH] drivers/md: fix potential mem leak



-----邮件原件-----
发件人: [email protected] <[email protected]> 代表 Song Liu
发送时间: 2021年11月17日 15:06
收件人: 赵军奎 <[email protected]>
抄送: linux-raid <[email protected]>; open list <[email protected]>
主题: Re: [PATCH] drivers/md: fix potential memleak

On Sun, Nov 14, 2021 at 7:18 PM Bernard Zhao <[email protected]> wrote:
>
> In function get_bitmap_from_slot, when md_bitmap_create failed,
> md_bitmap_destroy must be called to do clean up.

>Could you please explain which variable(s) need clean up?

Hi Song:
The follow is the function md_bitmap_create`s annotation :
/*
* initialize the bitmap structure
* if this returns an error, bitmap_destroy must be called to do clean up
* once mddev->bitmap is set
*/
struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)

It is mentioned that bitmap_destroy needs to be called to do clean up.
Other functions which called md_bitmap_create in the same file also called md_bitmap_create to clean up(in the error branch), but this one didn`t.
I am not sure if there is some gap?
Thanks!
BR//Bernard

>Thanks,
>Song

>
> Signed-off-by: Bernard Zhao <[email protected]>
> ---
> drivers/md/md-bitmap.c | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/drivers/md/md-bitmap.c b/drivers/md/md-bitmap.c index
> bfd6026d7809..a227bd0b9301 100644
> --- a/drivers/md/md-bitmap.c
> +++ b/drivers/md/md-bitmap.c
> @@ -1961,6 +1961,7 @@ struct bitmap *get_bitmap_from_slot(struct mddev *mddev, int slot)
> bitmap = md_bitmap_create(mddev, slot);
> if (IS_ERR(bitmap)) {
> rv = PTR_ERR(bitmap);
> + md_bitmap_destroy(mddev)
> return ERR_PTR(rv);
> }
>
> --
> 2.33.1
>


2021-11-20 07:24:04

by Song Liu

[permalink] [raw]
Subject: Re: [PATCH] drivers/md: fix potential memleak

On Tue, Nov 16, 2021 at 9:57 PM 赵军奎 <[email protected]> wrote:
>
>
>
> -----邮件原件-----
> 发件人: [email protected] <[email protected]> 代表 Song Liu
> 发送时间: 2021年11月17日 15:06
> 收件人: 赵军奎 <[email protected]>
> 抄送: linux-raid <[email protected]>; open list <[email protected]>
> 主题: Re: [PATCH] drivers/md: fix potential memleak
>
> On Sun, Nov 14, 2021 at 7:18 PM Bernard Zhao <[email protected]> wrote:
> >
> > In function get_bitmap_from_slot, when md_bitmap_create failed,
> > md_bitmap_destroy must be called to do clean up.
>
> >Could you please explain which variable(s) need clean up?
>
> Hi Song:
> The follow is the function md_bitmap_create`s annotation :
> /*
> * initialize the bitmap structure
> * if this returns an error, bitmap_destroy must be called to do clean up
> * once mddev->bitmap is set
> */
> struct bitmap *md_bitmap_create(struct mddev *mddev, int slot)
>
> It is mentioned that bitmap_destroy needs to be called to do clean up.
> Other functions which called md_bitmap_create in the same file also called md_bitmap_create to clean up(in the error branch), but this one didn`t.
> I am not sure if there is some gap?

I don't think we need to call md_bitmap_destroy in some of these cases.
Please read the code carefully can decide where these are needed based
on the logic of the code.

Thanks,
Song