[PATCH 2/7] secretXMLParseNode: Clean up freeing of memory

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

 



Use one variable per extracted property instead of reusing strings and
drop needless VIR_FREE calls.

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

diff --git a/src/conf/secret_conf.c b/src/conf/secret_conf.c
index 9cacc43e28..4d7d685d6e 100644
--- a/src/conf/secret_conf.c
+++ b/src/conf/secret_conf.c
@@ -131,7 +131,8 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
 {
     g_autoptr(xmlXPathContext) ctxt = NULL;
     g_autoptr(virSecretDef) def = NULL;
-    g_autofree char *prop = NULL;
+    g_autofree char *ephemeralstr = NULL;
+    g_autofree char *privatestr = NULL;
     g_autofree char *uuidstr = NULL;

     if (!virXMLNodeNameEqual(root, "secret")) {
@@ -149,24 +150,20 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)

     def = g_new0(virSecretDef, 1);

-    prop = virXPathString("string(./@ephemeral)", ctxt);
-    if (prop != NULL) {
-        if (virStringParseYesNo(prop, &def->isephemeral) < 0) {
+    if ((ephemeralstr = virXPathString("string(./@ephemeral)", ctxt))) {
+        if (virStringParseYesNo(ephemeralstr, &def->isephemeral) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid value of 'ephemeral'"));
             return NULL;
         }
-        VIR_FREE(prop);
     }

-    prop = virXPathString("string(./@private)", ctxt);
-    if (prop != NULL) {
-        if (virStringParseYesNo(prop, &def->isprivate) < 0) {
+    if ((privatestr = virXPathString("string(./@private)", ctxt))) {
+        if (virStringParseYesNo(privatestr, &def->isprivate) < 0) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("invalid value of 'private'"));
             return NULL;
         }
-        VIR_FREE(prop);
     }

     uuidstr = virXPathString("string(./uuid)", ctxt);
@@ -182,7 +179,6 @@ secretXMLParseNode(xmlDocPtr xml, xmlNodePtr root)
                            "%s", _("malformed uuid element"));
             return NULL;
         }
-        VIR_FREE(uuidstr);
     }

     def->description = virXPathString("string(./description)", ctxt);
-- 
2.29.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