[PATCH 5/9] conf: Use VIR_AUTOPTR for xmlDoc and xmlXPath objects

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

 



Refactor functions using these two object types together with
VIR_AUTOPTR.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/domain_conf.c  | 16 +++++-----------
 src/conf/storage_conf.c | 20 +++++++-------------
 2 files changed, 12 insertions(+), 24 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 0ab69a9366..5fec2e5220 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -16508,20 +16508,19 @@ virDomainDiskDefParse(const char *xmlStr,
                       virDomainXMLOptionPtr xmlopt,
                       unsigned int flags)
 {
-    xmlDocPtr xml;
-    xmlXPathContextPtr ctxt = NULL;
-    virDomainDiskDefPtr disk = NULL;
+    VIR_AUTOPTR(xmlDoc) xml = NULL;
+    VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
     virSecurityLabelDefPtr *seclabels = NULL;
     size_t nseclabels = 0;

     if (!(xml = virXMLParseStringCtxt(xmlStr, _("(disk_definition)"), &ctxt)))
-        goto cleanup;
+        return NULL;

     if (!virXMLNodeNameEqual(ctxt->node, "disk")) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("expecting root element of 'disk', not '%s'"),
                        ctxt->node->name);
-        goto cleanup;
+        return NULL;
     }

     if (def) {
@@ -16529,13 +16528,8 @@ virDomainDiskDefParse(const char *xmlStr,
         nseclabels = def->nseclabels;
     }

-    disk = virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt,
+    return virDomainDiskDefParseXML(xmlopt, ctxt->node, ctxt,
                                     seclabels, nseclabels, flags);
-
- cleanup:
-    xmlFreeDoc(xml);
-    xmlXPathFreeContext(ctxt);
-    return disk;
 }


diff --git a/src/conf/storage_conf.c b/src/conf/storage_conf.c
index f6de3687ab..fcd1701d37 100644
--- a/src/conf/storage_conf.c
+++ b/src/conf/storage_conf.c
@@ -695,36 +695,30 @@ virStoragePoolSourcePtr
 virStoragePoolDefParseSourceString(const char *srcSpec,
                                    int pool_type)
 {
-    xmlDocPtr doc = NULL;
+    VIR_AUTOPTR(xmlDoc) doc = NULL;
     xmlNodePtr node = NULL;
-    xmlXPathContextPtr xpath_ctxt = NULL;
-    virStoragePoolSourcePtr ret = NULL;
+    VIR_AUTOPTR(xmlXPathContext) xpath_ctxt = NULL;
     VIR_AUTOPTR(virStoragePoolSource) def = NULL;

     if (!(doc = virXMLParseStringCtxt(srcSpec,
                                       _("(storage_source_specification)"),
                                       &xpath_ctxt)))
-        goto cleanup;
+        return NULL;

     if (VIR_ALLOC(def) < 0)
-        goto cleanup;
+        return NULL;

     if (!(node = virXPathNode("/source", xpath_ctxt))) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("root element was not source"));
-        goto cleanup;
+        return NULL;
     }

     if (virStoragePoolDefParseSource(xpath_ctxt, def, pool_type,
                                      node) < 0)
-        goto cleanup;
-
-    VIR_STEAL_PTR(ret, def);
- cleanup:
-    xmlFreeDoc(doc);
-    xmlXPathFreeContext(xpath_ctxt);
+        return NULL;

-    return ret;
+    VIR_RETURN_PTR(def);
 }


-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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