]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
secretXMLParseNode: Clean up freeing of memory
authorPeter Krempa <pkrempa@redhat.com>
Wed, 6 Jan 2021 14:52:06 +0000 (15:52 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Fri, 8 Jan 2021 08:18:21 +0000 (09:18 +0100)
Use one variable per extracted property instead of reusing strings and
drop needless VIR_FREE calls.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/conf/secret_conf.c

index 9cacc43e28f1ecd55c57ec9c751058864750bde4..4d7d685d6e7e7a1dca941433c153b1294a043561 100644 (file)
@@ -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);