Fix memory leak after "mdadm --detail"

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
Signed-off-by: Jes Sorensen <jsorensen@fb.com>
This commit is contained in:
Mateusz Grzonka 2021-07-27 10:25:18 +02:00 committed by Jes Sorensen
parent 92a647c8a0
commit 7d374a1869
1 changed files with 9 additions and 11 deletions

View File

@ -66,11 +66,11 @@ int Detail(char *dev, struct context *c)
int spares = 0; int spares = 0;
struct stat stb; struct stat stb;
int failed = 0; int failed = 0;
struct supertype *st; struct supertype *st = NULL;
char *subarray = NULL; char *subarray = NULL;
int max_disks = MD_SB_DISKS; /* just a default */ int max_disks = MD_SB_DISKS; /* just a default */
struct mdinfo *info = NULL; struct mdinfo *info = NULL;
struct mdinfo *sra; struct mdinfo *sra = NULL;
struct mdinfo *subdev; struct mdinfo *subdev;
char *member = NULL; char *member = NULL;
char *container = NULL; char *container = NULL;
@ -93,8 +93,7 @@ int Detail(char *dev, struct context *c)
if (!sra) { if (!sra) {
if (md_get_array_info(fd, &array)) { if (md_get_array_info(fd, &array)) {
pr_err("%s does not appear to be an md device\n", dev); pr_err("%s does not appear to be an md device\n", dev);
close(fd); goto out;
return rv;
} }
} }
external = (sra != NULL && sra->array.major_version == -1 && external = (sra != NULL && sra->array.major_version == -1 &&
@ -108,16 +107,13 @@ int Detail(char *dev, struct context *c)
sra->devs == NULL) { sra->devs == NULL) {
pr_err("Array associated with md device %s does not exist.\n", pr_err("Array associated with md device %s does not exist.\n",
dev); dev);
close(fd); goto out;
sysfs_free(sra);
return rv;
} }
array = sra->array; array = sra->array;
} else { } else {
pr_err("cannot get array detail for %s: %s\n", pr_err("cannot get array detail for %s: %s\n",
dev, strerror(errno)); dev, strerror(errno));
close(fd); goto out;
return rv;
} }
} }
@ -827,10 +823,12 @@ out:
close(fd); close(fd);
free(subarray); free(subarray);
free(avail); free(avail);
for (d = 0; d < n_devices; d++) if (devices)
free(devices[d]); for (d = 0; d < n_devices; d++)
free(devices[d]);
free(devices); free(devices);
sysfs_free(sra); sysfs_free(sra);
free(st);
return rv; return rv;
} }