All of lore.kernel.org
 help / color / mirror / Atom feed
From: miaoguanqin <miaoguanqin@huawei.com>
To: <jes@trained-monkey.org>, <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: [PATCH 1/4] Fix memory leak in file Assemble
Date: Thu, 23 Mar 2023 09:30:50 +0800	[thread overview]
Message-ID: <20230323013053.3238005-2-miaoguanqin@huawei.com> (raw)
In-Reply-To: <20230323013053.3238005-1-miaoguanqin@huawei.com>

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: miaoguanqin <miaoguanqin@huawei.com>
Signed-off-by: lixiaokeng <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);
 			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);
 	/* '2' means 'OK, but not started yet' */
 	if (rv == -1) {
 		free(devices);
-- 
2.33.0


  reply	other threads:[~2023-03-23  1:49 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-23  1:30 [PATCH 0/4] Fix memory leak for Manage Assemble Kill mdadm miaoguanqin
2023-03-23  1:30 ` miaoguanqin [this message]
2023-03-28  7:54   ` [PATCH 1/4] Fix memory leak in file Assemble Mariusz Tkaczyk
2023-03-28 11:21   ` Paul Menzel
2023-03-23  1:30 ` [PATCH 2/4] Fix memory leak in file Kill miaoguanqin
2023-03-28  9:38   ` Mariusz Tkaczyk
2023-03-23  1:30 ` [PATCH 3/4] Fix memory leak in file Manage miaoguanqin
2023-03-28 10:28   ` Mariusz Tkaczyk
2023-03-23  1:30 ` [PATCH 4/4] Fix memory leak in file mdadm miaoguanqin
2023-03-28 10:29   ` Mariusz Tkaczyk
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
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

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=20230323013053.3238005-2-miaoguanqin@huawei.com \
    --to=miaoguanqin@huawei.com \
    --cc=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=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.