All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ruozhu Li <liruozhu@huawei.com>
To: <kbusch@kernel.org>, <linux-nvme@lists.infradead.org>
Cc: <jiangtao62@huawei.com>
Subject: [PATCH nvme-cli] nvme: fix some memory leak bugs
Date: Fri, 16 Jul 2021 14:10:40 +0800	[thread overview]
Message-ID: <20210716061040.21614-1-liruozhu@huawei.com> (raw)

Signed-off-by: Ruozhu Li <liruozhu@huawei.com>
---
 nvme-print.c | 6 +++++-
 nvme-rpmb.c  | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/nvme-print.c b/nvme-print.c
index 9444154..e808851 100755
--- a/nvme-print.c
+++ b/nvme-print.c
@@ -2618,6 +2618,8 @@ void nvme_show_relatives(const char *name)
 			comma = true;
 		}
 		fprintf(stderr, "\n\n");
+		for (i = 0; i < n; i++)
+			free(paths[i]);
 		free(paths);
 	}
 	free(path);
@@ -6382,8 +6384,10 @@ static void json_simple_ns(struct nvme_namespace *n, struct json_object *devices
 		return;
 
 	ret = stat(devnode, &st);
-	if (ret < 0)
+	if (ret < 0) {
+		free(devnode);
 		return;
+	}
 
 	device_attrs = json_create_object();
 	json_object_add_value_int(device_attrs, "NameSpace", n->nsid);
diff --git a/nvme-rpmb.c b/nvme-rpmb.c
index 0e11ef3..7dc0b58 100644
--- a/nvme-rpmb.c
+++ b/nvme-rpmb.c
@@ -278,7 +278,10 @@ static void rpmb_nonce_init(struct rpmb_data_frame_t *req)
 {
 	int num = rand();
 	unsigned char *hash = rpmb_md5((unsigned char *)&num, sizeof(num));
-	if (hash) memcpy(req->nonce, hash, sizeof(req->nonce));
+	if (hash) {
+		memcpy(req->nonce, hash, sizeof(req->nonce));
+		free(hash);
+	}
 }
 
 /* Read key from a given key buffer or key file */
-- 
2.25.1


_______________________________________________
Linux-nvme mailing list
Linux-nvme@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-nvme

                 reply	other threads:[~2021-07-16  6:11 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210716061040.21614-1-liruozhu@huawei.com \
    --to=liruozhu@huawei.com \
    --cc=jiangtao62@huawei.com \
    --cc=kbusch@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.