[PATCH 5/5] virXMLParseHelper: Refactor cleanup

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

 



Switch @xml and @pctxt to g_autofree and get rid of the "error" and
"cleanup" labels.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/util/virxml.c | 22 +++++++---------------
 1 file changed, 7 insertions(+), 15 deletions(-)

diff --git a/src/util/virxml.c b/src/util/virxml.c
index 029b3d646e..58d640546f 100644
--- a/src/util/virxml.c
+++ b/src/util/virxml.c
@@ -786,8 +786,8 @@ virXMLParseHelper(int domcode,
                   xmlXPathContextPtr *ctxt)
 {
     struct virParserData private;
-    xmlParserCtxtPtr pctxt;
-    xmlDocPtr xml = NULL;
+    g_autoptr(xmlParserCtxt) pctxt = NULL;
+    g_autoptr(xmlDoc) xml = NULL;
     const char *docname;

     if (filename)
@@ -823,32 +823,24 @@ virXMLParseHelper(int domcode,
                                   docname);
         }

-        goto error;
+        return NULL;
     }

     if (xmlDocGetRootElement(xml) == NULL) {
         virGenericReportError(domcode, VIR_ERR_INTERNAL_ERROR,
                               "%s", _("missing root element"));
-        goto error;
+
+        return NULL;
     }

     if (ctxt) {
         if (!(*ctxt = virXMLXPathContextNew(xml)))
-            goto error;
+            return NULL;

         (*ctxt)->node = xmlDocGetRootElement(xml);
     }

- cleanup:
-    xmlFreeParserCtxt(pctxt);
-
-    return xml;
-
- error:
-    xmlFreeDoc(xml);
-    xml = NULL;
-
-    goto cleanup;
+    return g_steal_pointer(&xml);
 }

 const char *virXMLPickShellSafeComment(const char *str1, const char *str2)
-- 
2.30.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