]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
hyperv: use GLib auto-cleanup in hypervDomainGetXMLDesc
authorMatt Coleman <mcoleman@datto.com>
Thu, 21 Jan 2021 18:51:28 +0000 (13:51 -0500)
committerLaine Stump <laine@redhat.com>
Fri, 22 Jan 2021 19:04:28 +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 bd3c5a7c34983ed8dbd325a706be00867629d0ca..e8296ead21ef8fc29423342233743e3f888ed6ce 100644 (file)
@@ -2117,52 +2117,51 @@ hypervDomainGetVcpus(virDomainPtr domain,
 static char *
 hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
 {
-    char *xml = NULL;
     hypervPrivate *priv = domain->conn->privateData;
-    virDomainDefPtr def = NULL;
+    g_autoptr(virDomainDef) def = NULL;
     char uuid_string[VIR_UUID_STRING_BUFLEN];
-    Msvm_ComputerSystem *computerSystem = NULL;
-    Msvm_VirtualSystemSettingData *virtualSystemSettingData = NULL;
-    Msvm_ProcessorSettingData *processorSettingData = NULL;
-    Msvm_MemorySettingData *memorySettingData = NULL;
-    Msvm_ResourceAllocationSettingData *rasd = NULL;
-    Msvm_StorageAllocationSettingData *sasd = NULL;
+    g_autoptr(Msvm_ComputerSystem) computerSystem = NULL;
+    g_autoptr(Msvm_VirtualSystemSettingData) virtualSystemSettingData = NULL;
+    g_autoptr(Msvm_ProcessorSettingData) processorSettingData = NULL;
+    g_autoptr(Msvm_MemorySettingData) memorySettingData = NULL;
+    g_autoptr(Msvm_ResourceAllocationSettingData) rasd = NULL;
+    g_autoptr(Msvm_StorageAllocationSettingData) sasd = NULL;
 
     virCheckFlags(VIR_DOMAIN_XML_COMMON_FLAGS, NULL);
 
     if (!(def = virDomainDefNew()))
-        goto cleanup;
+        return NULL;
 
     virUUIDFormat(domain->uuid, uuid_string);
 
     /* Get Msvm_ComputerSystem */
     if (hypervMsvmComputerSystemFromDomain(domain, &computerSystem) < 0)
-        goto cleanup;
+        return NULL;
 
     if (hypervGetMsvmVirtualSystemSettingDataFromUUID(priv, uuid_string,
                                                       &virtualSystemSettingData) < 0)
-        goto cleanup;
+        return NULL;
 
     if (hypervGetProcessorSD(priv,
                              virtualSystemSettingData->data->InstanceID,
                              &processorSettingData) < 0)
-        goto cleanup;
+        return NULL;
 
     if (hypervGetMemorySD(priv,
                           virtualSystemSettingData->data->InstanceID,
                           &memorySettingData) < 0)
-        goto cleanup;
+        return NULL;
 
     if (hypervGetResourceAllocationSD(priv,
                                       virtualSystemSettingData->data->InstanceID,
                                       &rasd) < 0) {
-        goto cleanup;
+        return NULL;
     }
 
     if (hypervGetStorageAllocationSD(priv,
                                      virtualSystemSettingData->data->InstanceID,
                                      &sasd) < 0) {
-        goto cleanup;
+        return NULL;
     }
 
     /* Fill struct */
@@ -2207,10 +2206,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     virDomainDefSetMemoryTotal(def, memorySettingData->data->VirtualQuantity * 1024);
 
     if (virDomainDefSetVcpusMax(def, processorSettingData->data->VirtualQuantity, NULL) < 0)
-        goto cleanup;
+        return NULL;
 
     if (virDomainDefSetVcpus(def, processorSettingData->data->VirtualQuantity) < 0)
-        goto cleanup;
+        return NULL;
 
     def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
@@ -2227,22 +2226,10 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     def->ncontrollers = 0;
 
     if (hypervDomainDefParseStorage(priv, def, rasd, sasd) < 0)
-        goto cleanup;
+        return NULL;
 
     /* XXX xmlopts must be non-NULL */
-    xml = virDomainDefFormat(def, NULL,
-                             virDomainDefFormatConvertXMLFlags(flags));
-
- cleanup:
-    virDomainDefFree(def);
-    hypervFreeObject((hypervObject *)computerSystem);
-    hypervFreeObject((hypervObject *)virtualSystemSettingData);
-    hypervFreeObject((hypervObject *)processorSettingData);
-    hypervFreeObject((hypervObject *)memorySettingData);
-    hypervFreeObject((hypervObject *)rasd);
-    hypervFreeObject((hypervObject *)sasd);
-
-    return xml;
+    return virDomainDefFormat(def, NULL, virDomainDefFormatConvertXMLFlags(flags));
 }