Linux-Raid Archives mirror
 help / color / mirror / Atom feed
* [PATCH] Fix memory leak after "mdadm --detail"
@ 2021-07-27  8:25 Mateusz Grzonka
  2021-08-02 14:03 ` Jes Sorensen
  0 siblings, 1 reply; 2+ messages in thread
From: Mateusz Grzonka @ 2021-07-27  8:25 UTC (permalink / raw
  To: linux-raid; +Cc: jes

Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>
---
 Detail.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/Detail.c b/Detail.c
index ad56344f..d3af0ab5 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;
 }
 
-- 
2.26.2


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Fix memory leak after "mdadm --detail"
  2021-07-27  8:25 [PATCH] Fix memory leak after "mdadm --detail" Mateusz Grzonka
@ 2021-08-02 14:03 ` Jes Sorensen
  0 siblings, 0 replies; 2+ messages in thread
From: Jes Sorensen @ 2021-08-02 14:03 UTC (permalink / raw
  To: Mateusz Grzonka, linux-raid

On 7/27/21 4:25 AM, Mateusz Grzonka wrote:
> Signed-off-by: Mateusz Grzonka <mateusz.grzonka@intel.com>

Applied!

Thanks,
Jes



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2021-08-02 14:05 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-27  8:25 [PATCH] Fix memory leak after "mdadm --detail" Mateusz Grzonka
2021-08-02 14:03 ` Jes Sorensen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).