[PATCH 19/21] domain_conf.c: modernize virDomainDefControllersParse()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The 'error' label is just returning -1, so let's 'return -1'
directly.

Use g_autoptr() with virDomainControllerDefPtr to remove the
need to call virDomainControllerDefFree() in the error path.

There is no need to VIR_FREE(nodes) explictly since 'nodes'
is using g_autofree.

Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx>
---
 src/conf/domain_conf.c | 26 ++++++++++----------------
 1 file changed, 10 insertions(+), 16 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5630f72096..b794611b1e 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -21819,38 +21819,36 @@ virDomainDefControllersParse(virDomainDefPtr def,
     int n;
 
     if ((n = virXPathNodeSet("./devices/controller", ctxt, &nodes)) < 0)
-        goto error;
+        return -1;
 
     if (n)
         def->controllers = g_new0(virDomainControllerDefPtr, n);
 
     for (i = 0; i < n; i++) {
-        virDomainControllerDefPtr controller = virDomainControllerDefParseXML(xmlopt,
-                                                                              nodes[i],
-                                                                              ctxt,
-                                                                              flags);
+        g_autoptr(virDomainControllerDef) controller = NULL;
+
+        controller = virDomainControllerDefParseXML(xmlopt, nodes[i],
+                                                    ctxt, flags);
 
         if (!controller)
-            goto error;
+            return -1;
 
         /* sanitize handling of "none" usb controller */
         if (controller->type == VIR_DOMAIN_CONTROLLER_TYPE_USB) {
             if (controller->model == VIR_DOMAIN_CONTROLLER_MODEL_USB_NONE) {
                 if (usb_other || *usb_none) {
-                    virDomainControllerDefFree(controller);
                     virReportError(VIR_ERR_XML_DETAIL, "%s",
                                    _("Can't add another USB controller: "
                                      "USB is disabled for this domain"));
-                    goto error;
+                    return -1;
                 }
                 *usb_none = true;
             } else {
                 if (*usb_none) {
-                    virDomainControllerDefFree(controller);
                     virReportError(VIR_ERR_XML_DETAIL, "%s",
                                    _("Can't add another USB controller: "
                                      "USB is disabled for this domain"));
-                    goto error;
+                    return -1;
                 }
                 usb_other = true;
             }
@@ -21859,20 +21857,16 @@ virDomainDefControllersParse(virDomainDefPtr def,
                 usb_master = true;
         }
 
-        virDomainControllerInsertPreAlloced(def, controller);
+        virDomainControllerInsertPreAlloced(def, g_steal_pointer(&controller));
     }
-    VIR_FREE(nodes);
 
     if (usb_other && !usb_master) {
         virReportError(VIR_ERR_XML_DETAIL, "%s",
                        _("No master USB controller specified"));
-        goto error;
+        return -1;
     }
 
     return 0;
-
- error:
-    return -1;
 }
 
 static virDomainDefPtr
-- 
2.26.2




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux