From: Ján Tomko Date: Wed, 11 Aug 2021 11:31:32 +0000 (+0200) Subject: conf: virCPUDefListParse: reduce scope of variables X-Git-Tag: v7.7.0-rc1~174 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1550892e854ee7b38d5ebaa8a6f36a0100cf7405;p=thirdparty%2Flibvirt.git 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 Reviewed-by: Martin Kletzander Reviewed-by: Pavel Hrdina --- 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; }