[PATCH 09/30] util: convert pointers to use g_autofree

Ryan Gahagan rgahagan at cs.utexas.edu
Mon Nov 23 22:09:30 UTC 2020


From: Barrett Schonefeld <bschoney at utexas.edu>

- src/util/virscsihost.c

Signed-off-by: Barrett Schonefeld <bschoney at utexas.edu>
---
 src/util/virscsihost.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/util/virscsihost.c b/src/util/virscsihost.c
index 969cdd9f79..2ce33e4cfb 100644
--- a/src/util/virscsihost.c
+++ b/src/util/virscsihost.c
@@ -95,12 +95,12 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
     const char *prefix = sysfs_prefix ? sysfs_prefix : SYSFS_SCSI_HOST_PATH;
     struct dirent *entry = NULL;
     g_autoptr(DIR) dir = NULL;
-    char *host_link = NULL;
-    char *host_path = NULL;
+    g_autofree char *host_link = NULL;
+    g_autofree char *host_path = NULL;
     char *p = NULL;
     char *ret = NULL;
-    char *buf = NULL;
-    char *unique_path = NULL;
+    g_autofree char *buf = NULL;
+    g_autofree char *unique_path = NULL;
     unsigned int read_unique_id;
 
     if (virDirOpen(&dir, prefix) < 0)
@@ -151,10 +151,6 @@ virSCSIHostFindByPCI(const char *sysfs_prefix,
     }
 
  cleanup:
-    VIR_FREE(unique_path);
-    VIR_FREE(host_link);
-    VIR_FREE(host_path);
-    VIR_FREE(buf);
     return ret;
 }
 
@@ -226,7 +222,7 @@ virSCSIHostGetNameByParentaddr(unsigned int domain,
                                unsigned int unique_id)
 {
     char *name = NULL;
-    char *parentaddr = NULL;
+    g_autofree char *parentaddr = NULL;
 
     parentaddr = g_strdup_printf("%04x:%02x:%02x.%01x", domain, bus, slot,
                                  function);
@@ -239,7 +235,6 @@ virSCSIHostGetNameByParentaddr(unsigned int domain,
     }
 
  cleanup:
-    VIR_FREE(parentaddr);
     return name;
 }
 
-- 
2.29.0




More information about the libvir-list mailing list