diff --git a/0031-Fix-memory-leak-in-file-Kill.patch b/0031-Fix-memory-leak-in-file-Kill.patch new file mode 100644 index 0000000000000000000000000000000000000000..4ed0ffe37b80c87630f590d186316b272be923b2 --- /dev/null +++ b/0031-Fix-memory-leak-in-file-Kill.patch @@ -0,0 +1,54 @@ +From 8fd0c565b09ba449418d7d604ceba66313246152 Mon Sep 17 00:00:00 2001 +From: Guanqin Miao +Date: Wed, 11 Sep 2024 13:53:54 +0800 +Subject: [PATCH] Fix memory leak in file Kill + +When we test mdadm with asan, we found some memory leaks in Kill.c +We fix these memory leaks based on code logic. + +Signed-off-by: Guanqin Miao +Signed-off-by: Li Xiao Keng +Acked-by: Mariusz Tkaczyk +Signed-off-by: Jes Sorensen +--- + Kill.c | 9 ++++++++- + 1 file changed, 8 insertions(+), 1 deletion(-) + +diff --git a/Kill.c b/Kill.c +index bfd0efd..43c9abe 100644 +--- a/Kill.c ++++ b/Kill.c +@@ -41,6 +41,7 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) + * 4 - failed to find a superblock. + */ + ++ bool free_super = false; + int fd, rv = 0; + + if (force) +@@ -52,8 +53,10 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) + dev); + return 2; + } +- if (st == NULL) ++ if (st == NULL) { + st = guess_super(fd); ++ free_super = true; ++ } + if (st == NULL || st->ss->init_super == NULL) { + if (verbose >= 0) + pr_err("Unrecognised md component device - %s\n", dev); +@@ -77,6 +80,10 @@ int Kill(char *dev, struct supertype *st, int force, int verbose, int noexcl) + rv = 0; + } + } ++ if (free_super && st) { ++ st->ss->free_super(st); ++ free(st); ++ } + close(fd); + return rv; + } +-- +2.23.0 + diff --git a/mdadm.spec b/mdadm.spec index 44dd975a0e6a982d7a143c75ba7bed853d88e1d6..d378bf7fbca8a699a0285bf66c08bc1fd6506b41 100644 --- a/mdadm.spec +++ b/mdadm.spec @@ -1,6 +1,6 @@ Name: mdadm Version: 4.2 -Release: 18 +Release: 19 Summary: The software RAID arrays user manage tools License: GPLv2+ URL: http://www.kernel.org/pub/linux/utils/raid/mdadm/ @@ -40,6 +40,7 @@ Patch27: 0027-mdadm-mdopen-fix-coverity-issue-CHECKED_RETURN.patch Patch28: 0028-mdadm-super1-fix-coverity-issue-CHECKED_RETURN.patch Patch39: 0029-mdadm-util.c-fix-coverity-issues.patch Patch30: 0030-mdadm-sysfs.c-fix-coverity-issues.patch +Patch31: 0031-Fix-memory-leak-in-file-Kill.patch BuildRequires: systemd gcc binutils libudev-devel @@ -106,6 +107,9 @@ install -d -m 710 %{buildroot}/var/run/mdadm/ %{_mandir}/man*/* %changelog +* Wed Sep 11 2024 cenhuilin - 4.2-19 +- Fix memory leak in file Kill + * Mon Aug 26 2024 wuguanghao - 4.2-18 - backport bugfix patches from community