diff mbox series

[3/4] Fix memory leak in file Manage

Message ID 20230424080637.2152893-4-miaoguanqin@huawei.com (mailing list archive)
State Mainlined, archived
Delegated to: Jes Sorensen
Headers show
Series Fix memory leak for Manage Assemble Kill mdadm | expand

Commit Message

Guanqin Miao April 24, 2023, 8:06 a.m. UTC
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: Guanqin Miao <miaoguanqin@huawei.com>
Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com>
---
 Manage.c | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

Comments

Mariusz Tkaczyk Aug. 23, 2023, 1:50 p.m. UTC | #1
On Mon, 24 Apr 2023 16:06:36 +0800
Guanqin Miao <miaoguanqin@huawei.com> wrote:

> 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: Guanqin Miao <miaoguanqin@huawei.com>
> Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com>
> ---
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
diff mbox series

Patch

diff --git a/Manage.c b/Manage.c
index f54de7c6..7b6b2798 100644
--- a/Manage.c
+++ b/Manage.c
@@ -222,6 +222,7 @@  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);
+		sysfs_free(mdi);
 		return 1;
 	}
 	/* If this is an mdmon managed array, just write 'inactive'
@@ -801,8 +802,14 @@  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) {
+					free(dev_st);
 					return rv;
+				}
+			}
+			if (dev_st) {
+				dev_st->ss->free_super(dev_st);
+				free(dev_st);
 			}
 		}
 		if (dv->disposition == 'M') {
@@ -1699,6 +1706,7 @@  int Manage_subdevs(char *devname, int fd,
 			break;
 		}
 	}
+	free(tst);
 	if (frozen > 0)
 		sysfs_set_str(&info, NULL, "sync_action","idle");
 	if (test && count == 0)
@@ -1706,6 +1714,7 @@  int Manage_subdevs(char *devname, int fd,
 	return 0;
 
 abort:
+	free(tst);
 	if (frozen > 0)
 		sysfs_set_str(&info, NULL, "sync_action","idle");
 	return !test && busy ? 2 : 1;