From: Alexander <>
Date: Sat, 30 May 2026 11:32:43 +0300
Subject: Free enumerator on errors

---
 src/device_discovery_linux.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/src/device_discovery_linux.c b/src/device_discovery_linux.c
index 1c5e5df..fdb1f76 100644
--- a/src/device_discovery_linux.c
+++ b/src/device_discovery_linux.c
@@ -339,19 +339,21 @@ int nvtop_device_current_pcie_link(nvtop_device *dev, nvtop_pcie_link *pcie_info
 
 nvtop_device *nvtop_device_get_hwmon(nvtop_device *dev) {
   nvtop_device_enumerator *enumerator;
+  nvtop_device *hwmon = NULL;
   int ret = nvtop_enumerator_new(&enumerator);
   if (ret < 0)
     return NULL;
   ret = nvtop_device_enumerator_add_match_subsystem(enumerator, "hwmon", true);
   if (ret < 0)
-    return NULL;
+    goto err;
   ret = nvtop_device_enumerator_add_match_parent(enumerator, dev);
   if (ret < 0)
-    return NULL;
-  nvtop_device *hwmon = nvtop_enumerator_get_device_first(enumerator);
+    goto err;
+  hwmon = nvtop_enumerator_get_device_first(enumerator);
   if (!hwmon)
-    return NULL;
+    goto err;
   nvtop_device_ref(hwmon);
+err:
   nvtop_enumerator_unref(enumerator);
   return hwmon;
 }
