All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jes Sorensen <jes@trained-monkey.org>
To: Guanqin Miao <miaoguanqin@huawei.com>,
	mariusz.tkaczyk@linux.intel.com, pmenzel@molgen.mpg.de,
	linux-raid@vger.kernel.org
Cc: linfeilong@huawei.com, lixiaokeng@huawei.com, louhongxiang@huawei.com
Subject: Re: [PATCH 1/4] Fix memory leak in file Assemble
Date: Mon, 10 Apr 2023 11:54:26 -0400	[thread overview]
Message-ID: <11cb6526-1848-bffb-f847-d856e7742777@trained-monkey.org> (raw)
In-Reply-To: <20230406114011.3297545-2-miaoguanqin@huawei.com>

On 4/6/23 07:40, Guanqin Miao wrote:
> When we test mdadm with asan, we found some memory leaks in Assemble.c
> We fix these memory leaks based on code logic.
> 
> Signed-off-by: Guanqin Miao <miaoguanqin@huawei.com>
> Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com>
> ---
>  Assemble.c | 15 +++++++++++++--
>  1 file changed, 13 insertions(+), 2 deletions(-)
> 
> diff --git a/Assemble.c b/Assemble.c
> index 49804941..574865eb 100644
> --- a/Assemble.c
> +++ b/Assemble.c
> @@ -341,8 +341,10 @@ static int select_devices(struct mddev_dev *devlist,
>  				st->ss->free_super(st);
>  			dev_policy_free(pol);
>  			domain_free(domains);
> -			if (tst)
> +			if (tst) {
>  				tst->ss->free_super(tst);
> +				free(tst);
> +			}
>  			return -1;
>  		}
>  
> @@ -417,6 +419,7 @@ static int select_devices(struct mddev_dev *devlist,
>  				st->ss->free_super(st);
>  				dev_policy_free(pol);
>  				domain_free(domains);
> +				free(st);
>  				return -1;
>  			}
>  			if (c->verbose > 0)
> @@ -425,6 +428,8 @@ static int select_devices(struct mddev_dev *devlist,
>  
>  			/* make sure we finished the loop */
>  			tmpdev = NULL;
> +			if (st)
> +				free(st);

free(NULL) is valid

>  			goto loop;
>  		} else {
>  			content = *contentp;
> @@ -533,6 +538,7 @@ static int select_devices(struct mddev_dev *devlist,
>  				st->ss->free_super(st);
>  				dev_policy_free(pol);
>  				domain_free(domains);
> +				free(tst);
>  				return -1;
>  			}
>  			tmpdev->used = 1;
> @@ -546,8 +552,10 @@ static int select_devices(struct mddev_dev *devlist,
>  		}
>  		dev_policy_free(pol);
>  		pol = NULL;
> -		if (tst)
> +		if (tst) {
>  			tst->ss->free_super(tst);
> +			free(tst);
> +		}
>  	}
>  
>  	/* Check if we found some imsm spares but no members */
> @@ -839,6 +847,7 @@ static int load_devices(struct devs *devices, char *devmap,
>  				close(mdfd);
>  				free(devices);
>  				free(devmap);
> +				free(best);
>  				*stp = st;
>  				return -1;
>  			}
> @@ -1950,6 +1959,8 @@ out:
>  	} else if (mdfd >= 0)
>  		close(mdfd);
>  
> +	if (best)
> +		free(best);

Same here

>  	/* '2' means 'OK, but not started yet' */
>  	if (rv == -1) {
>  		free(devices);


  reply	other threads:[~2023-04-10 15:55 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-06 11:40 [PATCH 0/4] Fix memory leak for Manage Assemble Kill mdadm Guanqin Miao
2023-04-06 11:40 ` [PATCH 1/4] Fix memory leak in file Assemble Guanqin Miao
2023-04-10 15:54   ` Jes Sorensen [this message]
2023-04-06 11:40 ` [PATCH 2/4] Fix memory leak in file Kill Guanqin Miao
2023-04-06 11:40 ` [PATCH 3/4] Fix memory leak in file Manage Guanqin Miao
2023-04-10 15:55   ` Jes Sorensen
2023-04-06 11:40 ` [PATCH 4/4] Fix memory leak in file mdadm Guanqin Miao
  -- strict thread matches above, loose matches on Subject: below --
2023-04-24  8:06 [PATCH 0/4] Fix memory leak for Manage Assemble Kill mdadm Guanqin Miao
2023-04-24  8:06 ` [PATCH 1/4] Fix memory leak in file Assemble Guanqin Miao
2023-08-23 13:43   ` Mariusz Tkaczyk
2023-03-23  1:30 [PATCH 0/4] Fix memory leak for Manage Assemble Kill mdadm miaoguanqin
2023-03-23  1:30 ` [PATCH 1/4] Fix memory leak in file Assemble miaoguanqin
2023-03-28  7:54   ` Mariusz Tkaczyk
2023-03-28 11:21   ` Paul Menzel

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=11cb6526-1848-bffb-f847-d856e7742777@trained-monkey.org \
    --to=jes@trained-monkey.org \
    --cc=linfeilong@huawei.com \
    --cc=linux-raid@vger.kernel.org \
    --cc=lixiaokeng@huawei.com \
    --cc=louhongxiang@huawei.com \
    --cc=mariusz.tkaczyk@linux.intel.com \
    --cc=miaoguanqin@huawei.com \
    --cc=pmenzel@molgen.mpg.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.