1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-03-07 17:28:15 +00:00

conf: virCPUDefListParse: reduce scope of variables

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>
This commit is contained in:
Ján Tomko 2021-08-11 13:31:32 +02:00
parent c6c3dd5971
commit 1550892e85

View 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;
}