Skip to content

Commit

Permalink
Fix memory leak in file Kill
Browse files Browse the repository at this point in the history
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 <[email protected]>
Signed-off-by: Li Xiao Keng <[email protected]>
Acked-by: Mariusz Tkaczyk <[email protected]>
Signed-off-by: Jes Sorensen <[email protected]>
  • Loading branch information
Guanqinm authored and jessorensen committed Sep 1, 2023
1 parent e9fb93a commit 8fd0c56
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Kill.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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);
Expand All @@ -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;
}
Expand Down

0 comments on commit 8fd0c56

Please sign in to comment.