From 39892e6f2eedf78877765cbfcc801732ebdfee68 Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Thu, 15 Sep 2022 17:58:32 +0200 Subject: [PATCH] virDomainNetIPInfoParseXML: Don't VIR_FREE and overwrite autofreed 'nodes' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use two separate variables for the nodes and count instead. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko --- src/conf/domain_conf.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c index 292bd1937c..26a24ecd55 100644 --- a/src/conf/domain_conf.c +++ b/src/conf/domain_conf.c @@ -6216,31 +6216,32 @@ virDomainNetIPInfoParseXML(const char *source, xmlXPathContextPtr ctxt, virNetDevIPInfo *def) { - int nnodes; int ret = -1; size_t i; - g_autofree xmlNodePtr *nodes = NULL; + g_autofree xmlNodePtr *ipNodes = NULL; + int nipNodes; + g_autofree xmlNodePtr *routeNodes = NULL; + int nrouteNodes; - if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0) + if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0) goto cleanup; - for (i = 0; i < nnodes; i++) { + for (i = 0; i < nipNodes; i++) { virNetDevIPAddr *ip = NULL; - if (!(ip = virDomainNetIPParseXML(nodes[i]))) + if (!(ip = virDomainNetIPParseXML(ipNodes[i]))) goto cleanup; VIR_APPEND_ELEMENT(def->ips, def->nips, ip); } - VIR_FREE(nodes); - if ((nnodes = virXPathNodeSet("./route", ctxt, &nodes)) < 0) + if ((nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0) goto cleanup; - for (i = 0; i < nnodes; i++) { + for (i = 0; i < nrouteNodes; i++) { virNetDevIPRoute *route = NULL; - if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt))) + if (!(route = virNetDevIPRouteParseXML(source, routeNodes[i], ctxt))) goto cleanup; VIR_APPEND_ELEMENT(def->routes, def->nroutes, route);