From 5a148f4b94fb047c6bbf4cdbc54504207560e94c Mon Sep 17 00:00:00 2001
From: Tomas Bzatek <tbzatek@redhat.com>
Date: Fri, 12 Jul 2024 15:13:33 +0800
Subject: [PATCH] nvme: Fix potential memory leak

This should not happen in practice when the NVMe spec
is thoroughly followed.
---
 src/plugins/nvme/nvme-info.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/plugins/nvme/nvme-info.c b/src/plugins/nvme/nvme-info.c
index eaf7747..947b1f0 100644
--- a/src/plugins/nvme/nvme-info.c
+++ b/src/plugins/nvme/nvme-info.c
@@ -672,16 +672,19 @@ BDNVMENamespaceInfo *bd_nvme_get_namespace_info (const gchar *device, GError **e
 
             switch (d->nidt) {
                 case NVME_NIDT_EUI64:
+                    g_free (info->eui64);
                     info->eui64 = g_malloc0 (d->nidl * 2 + 1);
                     for (i = 0; i < d->nidl; i++)
                         snprintf (info->eui64 + i * 2, 3, "%02x", d->nid[i]);
                     break;
                 case NVME_NIDT_NGUID:
+                    g_free (info->nguid);
                     info->nguid = g_malloc0 (d->nidl * 2 + 1);
                     for (i = 0; i < d->nidl; i++)
                         snprintf (info->nguid + i * 2, 3, "%02x", d->nid[i]);
                     break;
                 case NVME_NIDT_UUID:
+                    g_free (info->uuid);
                     info->uuid = _uuid_to_str (d->nid);
                     break;
                 case NVME_NIDT_CSI:
-- 
2.33.0

