Skip to contentSkip to conversation

nvme: fix some memory leak bugs

PATCH New Ruozhu Li 1 participant 1 message Jul 16, 2021 NVMe

lore
Share & tools
lore

Ruozhu Li

author
#0 lore raw

PATCH 1/1 nvme: fix some memory leak bugs

---
 nvme-print.c | 6 +++++-
 nvme-rpmb.c  | 5 ++++-
 2 files changed, 9 insertions(+), 2 deletions(-)
nvme-print.c +5 -1
index 9444154..e808851 100755
@@ -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);
nvme-rpmb.c +4 -1
index 0e11ef3..7dc0b58 100644
@@ -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 */
Signature · 7 lines
2.25.1


_______________________________________________
Linux-nvme mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-nvme