[libvirt PATCH 1/6] conf: virCPUDefListParse: reduce scope of variables

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

 



Move 'ctxt' and 'doc' inside the loop and mark them with g_auto.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 src/conf/cpu_conf.c | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/src/conf/cpu_conf.c b/src/conf/cpu_conf.c
index 58d04df1b8..44e62712c5 100644
--- a/src/conf/cpu_conf.c
+++ b/src/conf/cpu_conf.c
@@ -1126,8 +1126,6 @@ virCPUDefListParse(const char **xmlCPUs,
                    unsigned int ncpus,
                    virCPUType cpuType)
 {
-    xmlDocPtr doc = NULL;
-    xmlXPathContextPtr ctxt = NULL;
     virCPUDef **cpus = NULL;
     size_t i;
 
@@ -1152,24 +1150,20 @@ virCPUDefListParse(const char **xmlCPUs,
     cpus = g_new0(virCPUDef *, ncpus + 1);
 
     for (i = 0; i < ncpus; i++) {
+        g_autoptr(xmlDoc) doc = NULL;
+        g_autoptr(xmlXPathContext) ctxt = NULL;
+
         if (!(doc = virXMLParseStringCtxt(xmlCPUs[i], _("(CPU_definition)"), &ctxt)))
             goto error;
 
         if (virCPUDefParseXML(ctxt, NULL, cpuType, &cpus[i], false) < 0)
             goto error;
-
-        xmlXPathFreeContext(ctxt);
-        xmlFreeDoc(doc);
-        ctxt = NULL;
-        doc = NULL;
     }
 
     return cpus;
 
  error:
     virCPUDefListFree(cpus);
-    xmlXPathFreeContext(ctxt);
-    xmlFreeDoc(doc);
     return NULL;
 }
 
-- 
2.31.1




[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