Do the XPath fetches first as they don't require cleanup and rename
'cleanup' to 'error' and take it only on failure.

Signed-off-by: Peter Krempa <pkre...@redhat.com>
---
 src/conf/domain_conf.c | 22 +++++++++-------------
 1 file changed, 9 insertions(+), 13 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 797914b7bc..1b52ea52c4 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -6216,42 +6216,38 @@ virDomainNetIPInfoParseXML(const char *source,
                            xmlXPathContextPtr ctxt,
                            virNetDevIPInfo *def)
 {
-    int ret = -1;
     size_t i;
     g_autofree xmlNodePtr *ipNodes = NULL;
     int nipNodes;
     g_autofree xmlNodePtr *routeNodes = NULL;
     int nrouteNodes;

-    if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0)
-        goto cleanup;
+    if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0 ||
+        (nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0)
+        return -1;

     for (i = 0; i < nipNodes; i++) {
         virNetDevIPAddr *ip = NULL;

         if (!(ip = virDomainNetIPParseXML(ipNodes[i])))
-            goto cleanup;
+            goto error;

         VIR_APPEND_ELEMENT(def->ips, def->nips, ip);
     }

-    if ((nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0)
-        goto cleanup;
-
     for (i = 0; i < nrouteNodes; i++) {
         virNetDevIPRoute *route = NULL;

         if (!(route = virNetDevIPRouteParseXML(source, routeNodes[i], ctxt)))
-            goto cleanup;
+            goto error;

         VIR_APPEND_ELEMENT(def->routes, def->nroutes, route);
     }

-    ret = 0;
- cleanup:
-    if (ret < 0)
-        virNetDevIPInfoClear(def);
-    return ret;
+    return 0;
+ error:
+    virNetDevIPInfoClear(def);
+    return -1;
 }


-- 
2.37.1

Reply via email to