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 3/4] Fix memory leak in file Manage
Date: Thu, 23 Mar 2023 09:30:52 +0800	[thread overview]
Message-ID: <20230323013053.3238005-4-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 Manage.c
We fix these memory leaks based on code logic.

Signed-off-by: miaoguanqin <miaoguanqin@huawei.com>
Signed-off-by: lixiaokeng <lixiaokeng@huawei.com>
---
 Manage.c | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/Manage.c b/Manage.c
index fde6aba3..75bed83b 100644
--- a/Manage.c
+++ b/Manage.c
@@ -222,6 +222,8 @@ int Manage_stop(char *devname, int fd, int verbose, int will_retry)
 		if (verbose >= 0)
 			pr_err("Cannot get exclusive access to %s:Perhaps a running process, mounted filesystem or active volume group?\n",
 			       devname);
+		if (mdi)
+			sysfs_free(mdi);
 		return 1;
 	}
 	/* If this is an mdmon managed array, just write 'inactive'
@@ -818,8 +820,16 @@ int Manage_add(int fd, int tfd, struct mddev_dev *dv,
 						    rdev, update, devname,
 						    verbose, array);
 				dev_st->ss->free_super(dev_st);
-				if (rv)
+				if (rv) {
+					if (dev_st)
+						free(dev_st);
 					return rv;
+				}
+			}
+			if (dev_st) {
+				if (dev_st->sb)
+					dev_st->ss->free_super(dev_st);
+				free(dev_st);
 			}
 		}
 		if (dv->disposition == 'M') {
@@ -1716,6 +1726,8 @@ int Manage_subdevs(char *devname, int fd,
 			break;
 		}
 	}
+	if (tst)
+		free(tst);
 	if (frozen > 0)
 		sysfs_set_str(&info, NULL, "sync_action","idle");
 	if (test && count == 0)
@@ -1723,6 +1735,8 @@ int Manage_subdevs(char *devname, int fd,
 	return 0;
 
 abort:
+	if (tst)
+		free(tst);
 	if (frozen > 0)
 		sysfs_set_str(&info, NULL, "sync_action","idle");
 	return !test && busy ? 2 : 1;
-- 
2.33.0


  parent reply	other threads:[~2023-03-23  1:33 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 ` [PATCH 1/4] Fix memory leak in file Assemble miaoguanqin
2023-03-28  7:54   ` 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 ` miaoguanqin [this message]
2023-03-28 10:28   ` [PATCH 3/4] Fix memory leak in file Manage 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 3/4] Fix memory leak in file Manage Guanqin Miao
2023-04-10 15:55   ` 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 3/4] Fix memory leak in file Manage Guanqin Miao
2023-08-23 13:50   ` 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-4-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.