[libvirt PATCH 01/10] virDomainRedirFilterUSBDevDefParseXML: Use g_auto*

Tim Wiederhake twiederh at redhat.com
Tue May 4 14:02:26 UTC 2021


Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
---
 src/conf/domain_conf.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0050b952f3..5822f3d85a 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -14689,7 +14689,7 @@ virDomainRedirFilterUSBVersionHelper(const char *version,
 static virDomainRedirFilterUSBDevDef *
 virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
 {
-    virDomainRedirFilterUSBDevDef *def;
+    g_autofree virDomainRedirFilterUSBDevDef *def = NULL;
     g_autofree char *version = NULL;
     virTristateBool allow;
 
@@ -14697,42 +14697,38 @@ virDomainRedirFilterUSBDevDefParseXML(xmlNodePtr node)
 
     def->usbClass = -1;
     if (virXMLPropInt(node, "class", 0, VIR_XML_PROP_NONE, &def->usbClass) < 0)
-        goto error;
+        return NULL;
 
     if (def->usbClass != -1 && def->usbClass &~ 0xFF) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("Invalid USB Class code 0x%x"), def->usbClass);
-        goto error;
+        return NULL;
     }
 
     def->vendor = -1;
     if (virXMLPropInt(node, "vendor", 0, VIR_XML_PROP_NONE, &def->vendor) < 0)
-        goto error;
+        return NULL;
 
     def->product = -1;
     if (virXMLPropInt(node, "product", 0, VIR_XML_PROP_NONE, &def->product) < 0)
-        goto error;
+        return NULL;
 
     version = virXMLPropString(node, "version");
     if (version) {
         if (STREQ(version, "-1"))
             def->version = -1;
         else if ((virDomainRedirFilterUSBVersionHelper(version, def)) < 0)
-            goto error;
+            return NULL;
     } else {
         def->version = -1;
     }
 
     if (virXMLPropTristateBool(node, "allow", VIR_XML_PROP_REQUIRED, &allow) < 0)
-        goto error;
+        return NULL;
 
     def->allow = allow == VIR_TRISTATE_BOOL_YES;
 
-    return def;
-
- error:
-    VIR_FREE(def);
-    return NULL;
+    return g_steal_pointer(&def);
 }
 
 static virDomainRedirFilterDef *
-- 
2.26.3




More information about the libvir-list mailing list