diff options
author | Guanqin Miao <miaoguanqin@huawei.com> | 2023-04-24 10:06:35 +0200 |
---|---|---|
committer | Jes Sorensen <jes@trained-monkey.org> | 2023-09-01 18:08:06 +0200 |
commit | 8fd0c565b09ba449418d7d604ceba66313246152 (patch) | |
tree | 94c1a0165c8700541db68baee63af877c9e217ae /Kill.c | |
parent | Fix memory leak in file Assemble (diff) | |
download | mdadm-8fd0c565b09ba449418d7d604ceba66313246152.tar.xz mdadm-8fd0c565b09ba449418d7d604ceba66313246152.zip |
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 <miaoguanqin@huawei.com>
Signed-off-by: Li Xiao Keng <lixiaokeng@huawei.com>
Acked-by: Mariusz Tkaczyk <mariusz.tkaczyk@linux.intel.com>
Signed-off-by: Jes Sorensen <jes@trained-monkey.org>
Diffstat (limited to 'Kill.c')
-rw-r--r-- | Kill.c | 9 |
1 files changed, 8 insertions, 1 deletions
@@ -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; } |