]> xenbits.xensource.com Git - libvirt.git/commitdiff
hyperv: use g_autoptr for Win32_ComputerSystem in hypervConnectGetHostname
authorMatt Coleman <mcoleman@datto.com>
Thu, 21 Jan 2021 18:50:49 +0000 (13:50 -0500)
committerLaine Stump <laine@redhat.com>
Fri, 22 Jan 2021 19:04:25 +0000 (14:04 -0500)
Signed-off-by: Matt Coleman <matt@datto.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/hyperv/hyperv_driver.c

index 830a3414c58b3fcf32bf99fffc32327a174bcc54..8b59dd05f7fb8ae9ec8e9a144f157d707c16cd87 100644 (file)
@@ -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);
 }