From: Coly Li <colyli@suse.de>
To: miaoguanqin <miaoguanqin@huawei.com>
Cc: Jes Sorensen <jes@trained-monkey.org>,
Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>,
Paul Menzel <pmenzel@molgen.mpg.de>,
linux-raid@vger.kernel.org, linfeilong <linfeilong@huawei.com>,
"liuzhiqiang (I)" <liuzhiqiang26@huawei.com>,
Wu Guanghao <wuguanghao3@huawei.com>,
lixiaokeng@huawei.com
Subject: Re: [PATCH] Fix memory leak for function Manage_subdevs Manage_add Kill V2
Date: Thu, 23 Feb 2023 23:53:34 +0800 [thread overview]
Message-ID: <Y/eL/u9tvAXVDrfV@enigma.lan> (raw)
In-Reply-To: <5ab784a2-df14-62d7-873a-622b34b6a646@huawei.com>
On Wed, Feb 22, 2023 at 04:30:53PM +0800, miaoguanqin wrote:
> When we test mdadm with asan,we found some memory leaks.
> We fix these memory leaks based on code logic.
>
> Signed-off-by: miaoguanqin <miaoguanqin@huawei.com>
> ---
> Assemble.c | 16 +++++++++++++---
> Kill.c | 10 +++++++++-
> Manage.c | 16 +++++++++++++++-
> mdadm.c | 6 ++++++
> 4 files changed, 43 insertions(+), 5 deletions(-)
>
[snipped]
> diff --git a/Kill.c b/Kill.c
> index d4767e2..073288e 100644
> --- a/Kill.c
> +++ b/Kill.c
[snipped]
> @@ -77,6 +80,11 @@ int Kill(char *dev, struct supertype *st, int force, int
> verbose, int noexcl)
> rv = 0;
> }
> }
> + if (flags == 1 && st) {
> + if (st->sb)
> + free(st->sb);
May I ask why not call st->ss->free_super(st) ?
> + free(st);
> + }
> close(fd);
> return rv;
> }
[snipped]
> diff --git a/mdadm.c b/mdadm.c
> index da66c76..981fa98 100644
> --- a/mdadm.c
> +++ b/mdadm.c
> @@ -1765,6 +1765,12 @@ int main(int argc, char *argv[])
> autodetect();
> break;
> }
> + if (ss) {
> + if (ss->sb)
> + free(ss->sb);
Same question, why not call ss->ss->free_super(ss) ?
> + free(ss);
> +
> + }
> if (locked)
> cluster_release_dlmlock();
> if (mdfd > 0)
Overall the patch is fine to me. But it might be better to split it into
multiple patches that each has the changes for a single file.
Thanks.
--
Coly Li
next prev parent reply other threads:[~2023-02-23 15:53 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-02-22 8:30 [PATCH] Fix memory leak for function Manage_subdevs Manage_add Kill V2 miaoguanqin
2023-02-23 11:26 ` Mariusz Tkaczyk
2023-02-23 15:53 ` Coly Li [this message]
2023-03-13 14:17 ` Jes Sorensen
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=Y/eL/u9tvAXVDrfV@enigma.lan \
--to=colyli@suse.de \
--cc=jes@trained-monkey.org \
--cc=linfeilong@huawei.com \
--cc=linux-raid@vger.kernel.org \
--cc=liuzhiqiang26@huawei.com \
--cc=lixiaokeng@huawei.com \
--cc=mariusz.tkaczyk@linux.intel.com \
--cc=miaoguanqin@huawei.com \
--cc=pmenzel@molgen.mpg.de \
--cc=wuguanghao3@huawei.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).