summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMateusz Grzonka <mateusz.grzonka@intel.com>2021-07-27 10:25:18 +0200
committerJes Sorensen <jsorensen@fb.com>2021-08-02 10:03:38 -0400
commit7d374a1869d3a84971d027a7f4233878c8f25a62 (patch)
treee4287c379dfe09924a1b9d39d68feff975009fad
parent92a647c8a0ea26697967174fe24bc5cc47ce8f30 (diff)
downloadmdadm-7d374a1869d3a84971d027a7f4233878c8f25a62.tar.gz
Fix memory leak after "mdadm --detail"
Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com> Signed-off-by: Jes Sorensen <jsorensen@fb.com>
-rw-r--r--Detail.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Detail.c b/Detail.c
index ad56344..d3af0ab 100644
--- a/Detail.c
+++ b/Detail.c
@@ -66,11 +66,11 @@ int Detail(char *dev, struct context *c)
int spares = 0;
struct stat stb;
int failed = 0;
- struct supertype *st;
+ struct supertype *st = NULL;
char *subarray = NULL;
int max_disks = MD_SB_DISKS; /* just a default */
struct mdinfo *info = NULL;
- struct mdinfo *sra;
+ struct mdinfo *sra = NULL;
struct mdinfo *subdev;
char *member = NULL;
char *container = NULL;
@@ -93,8 +93,7 @@ int Detail(char *dev, struct context *c)
if (!sra) {
if (md_get_array_info(fd, &array)) {
pr_err("%s does not appear to be an md device\n", dev);
- close(fd);
- return rv;
+ goto out;
}
}
external = (sra != NULL && sra->array.major_version == -1 &&
@@ -108,16 +107,13 @@ int Detail(char *dev, struct context *c)
sra->devs == NULL) {
pr_err("Array associated with md device %s does not exist.\n",
dev);
- close(fd);
- sysfs_free(sra);
- return rv;
+ goto out;
}
array = sra->array;
} else {
pr_err("cannot get array detail for %s: %s\n",
dev, strerror(errno));
- close(fd);
- return rv;
+ goto out;
}
}
@@ -827,10 +823,12 @@ out:
close(fd);
free(subarray);
free(avail);
- for (d = 0; d < n_devices; d++)
- free(devices[d]);
+ if (devices)
+ for (d = 0; d < n_devices; d++)
+ free(devices[d]);
free(devices);
sysfs_free(sra);
+ free(st);
return rv;
}