From 1550892e854ee7b38d5ebaa8a6f36a0100cf7405 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A1n=20Tomko?= Date: Wed, 11 Aug 2021 13:31:32 +0200 Subject: [PATCH] conf: virCPUDefListParse: reduce scope of variables MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- 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; }