]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: domain: Refactor cleanup in virSysinfoParseXML
authorPeter Krempa <pkrempa@redhat.com>
Thu, 6 Oct 2022 10:33:08 +0000 (12:33 +0200)
committerPeter Krempa <pkrempa@redhat.com>
Wed, 2 Nov 2022 08:22:56 +0000 (09:22 +0100)
Use automatic pointer freeing to remove the 'error' label.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/domain_conf.c

index 2537aa808f6b9d0aab895c2b56f92efd3bf089a7..25288cc5a36bace66b391d3f0b2b896a6a59a95b 100644 (file)
@@ -12394,7 +12394,7 @@ virSysinfoParseXML(xmlNodePtr node,
                    bool uuid_generated)
 {
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
-    virSysinfoDef *def;
+    g_autoptr(virSysinfoDef) def = g_new0(virSysinfoDef, 1);
 
     ctxt->node = node;
 
@@ -12404,32 +12404,26 @@ virSysinfoParseXML(xmlNodePtr node,
         return NULL;
     }
 
-    def = g_new0(virSysinfoDef, 1);
-
     if (virXMLPropEnum(node, "type", virSysinfoTypeFromString,
                        VIR_XML_PROP_REQUIRED, &def->type) < 0)
-        goto error;
+        return NULL;
 
     switch (def->type) {
     case VIR_SYSINFO_SMBIOS:
         if (virSysinfoParseSMBIOSDef(def, ctxt, domUUID, uuid_generated) < 0)
-            goto error;
+            return NULL;
         break;
 
     case VIR_SYSINFO_FWCFG:
         if (virSysinfoParseFWCfgDef(def, node, ctxt) < 0)
-            goto error;
+            return NULL;
         break;
 
     case VIR_SYSINFO_LAST:
         break;
     }
 
-    return def;
-
- error:
-    virSysinfoDefFree(def);
-    return NULL;
+    return g_steal_pointer(&def);
 }
 
 unsigned int