[PATCH 09/55] hyperv: use g_autoptr for Win32_ComputerSystem in hypervConnectGetHostname

Matt Coleman mcoleman at datto.com
Thu Jan 21 18:50:49 UTC 2021


Signed-off-by: Matt Coleman <matt at datto.com>
---
 src/hyperv/hyperv_driver.c | 15 ++++-----------
 1 file changed, 4 insertions(+), 11 deletions(-)

diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 830a3414c5..8b59dd05f7 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -1493,19 +1493,12 @@ hypervConnectGetVersion(virConnectPtr conn, unsigned long *version)
 static char *
 hypervConnectGetHostname(virConnectPtr conn)
 {
-    char *hostname = NULL;
-    hypervPrivate *priv = conn->privateData;
-    Win32_ComputerSystem *computerSystem = NULL;
-
-    if (hypervGetPhysicalSystemList(priv, &computerSystem) < 0)
-        goto cleanup;
-
-    hostname = g_strdup(computerSystem->data->DNSHostName);
+    g_autoptr(Win32_ComputerSystem) computerSystem = NULL;
 
- cleanup:
-    hypervFreeObject((hypervObject *)computerSystem);
+    if (hypervGetPhysicalSystemList((hypervPrivate *)conn->privateData, &computerSystem) < 0)
+        return NULL;
 
-    return hostname;
+    return g_strdup(computerSystem->data->DNSHostName);
 }
 
 
-- 
2.30.0





More information about the libvir-list mailing list