[PATCH 9/9] conf: secret: Refactor cleanup in secretXMLParseNode

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

 



Use VIR_AUTO* for temporary locals and get rid of the 'cleanup' label.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 src/conf/secret_conf.c | 34 ++++++++++++++--------------------
 1 file changed, 14 insertions(+), 20 deletions(-)

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index a7691da7b5..da61c6917e 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -131,33 +131,33 @@ virSecretDefParseUsage(xmlXPathContextPtr ctxt,
 static virSecretDefPtr
 secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
 {
-    xmlXPathContextPtr ctxt = NULL;
-    virSecretDefPtr def = NULL, ret = NULL;
-    char *prop = NULL;
-    char *uuidstr = NULL;
+    VIR_AUTOPTR(xmlXPathContext) ctxt = NULL;
+    VIR_AUTOPTR(virSecretDef) def = NULL;
+    VIR_AUTOFREE(char *) prop = NULL;
+    VIR_AUTOFREE(char *) uuidstr = NULL;

     if (!virXMLNodeNameEqual(root, "secret")) {
         virReportError(VIR_ERR_XML_ERROR,
                        _("unexpected root element <%s>, "
                          "expecting <secret>"),
                        root->name);
-        goto cleanup;
+        return NULL;
     }

     if (!(ctxt = virXMLXPathContextNew(xml)))
-        goto cleanup;
+        return NULL;

     ctxt->node = root;

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

     prop = virXPathString("string(./@ephemeral)", ctxt);
     if (prop != NULL) {
         if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid value of 'ephemeral'"));
-            goto cleanup;
+            return NULL;
         }
         VIR_FREE(prop);
     }
@@ -167,7 +167,7 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
         if (virStringParseYesNo(prop, &def->isprivate) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid value of 'private'"));
-            goto cleanup;
+            return NULL;
         }
         VIR_FREE(prop);
     }
@@ -177,13 +177,13 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
         if (virUUIDGenerate(def->uuid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("Failed to generate UUID"));
-            goto cleanup;
+            return NULL;
         }
     } else {
         if (virUUIDParse(uuidstr, def->uuid) < 0) {
             virReportError(VIR_ERR_INTERNAL_ERROR,
                            "%s", _("malformed uuid element"));
-            goto cleanup;
+            return NULL;
         }
         VIR_FREE(uuidstr);
     }
@@ -191,15 +191,9 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
     def->description = virXPathString("string(./description)", ctxt);
     if (virXPathNode("./usage", ctxt) != NULL
         && virSecretDefParseUsage(ctxt, def) < 0)
-        goto cleanup;
-    VIR_STEAL_PTR(ret, def);
-
- cleanup:
-    VIR_FREE(prop);
-    VIR_FREE(uuidstr);
-    virSecretDefFree(def);
-    xmlXPathFreeContext(ctxt);
-    return ret;
+        return NULL;
+
+    VIR_RETURN_PTR(def);
 }

 static virSecretDefPtr
-- 
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