]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
conf: virCPUDefListParse: reduce scope of variables
authorJán Tomko <jtomko@redhat.com>
Wed, 11 Aug 2021 11:31:32 +0000 (13:31 +0200)
committerJán Tomko <jtomko@redhat.com>
Tue, 17 Aug 2021 16:27:13 +0000 (18:27 +0200)
Move 'ctxt' and 'doc' inside the loop and mark them with g_auto.

Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
src/conf/cpu_conf.c

index 58d04df1b8a7bb8f59b4029e436b3134597850d4..44e62712c5f092862d7d8beae3c4eab614807da1 100644 (file)
@@ -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;
 }