virDomainNetIPInfoParseXML: Don't VIR_FREE and overwrite autofreed 'nodes'

Use two separate variables for the nodes and count instead.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Peter Krempa 2022-09-15 17:58:32 +02:00
parent ecdbc4ea4e
commit 39892e6f2e

View File

@ -6216,31 +6216,32 @@ virDomainNetIPInfoParseXML(const char *source,
xmlXPathContextPtr ctxt, xmlXPathContextPtr ctxt,
virNetDevIPInfo *def) virNetDevIPInfo *def)
{ {
int nnodes;
int ret = -1; int ret = -1;
size_t i; 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; goto cleanup;
for (i = 0; i < nnodes; i++) { for (i = 0; i < nipNodes; i++) {
virNetDevIPAddr *ip = NULL; virNetDevIPAddr *ip = NULL;
if (!(ip = virDomainNetIPParseXML(nodes[i]))) if (!(ip = virDomainNetIPParseXML(ipNodes[i])))
goto cleanup; goto cleanup;
VIR_APPEND_ELEMENT(def->ips, def->nips, ip); 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; goto cleanup;
for (i = 0; i < nnodes; i++) { for (i = 0; i < nrouteNodes; i++) {
virNetDevIPRoute *route = NULL; virNetDevIPRoute *route = NULL;
if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt))) if (!(route = virNetDevIPRouteParseXML(source, routeNodes[i], ctxt)))
goto cleanup; goto cleanup;
VIR_APPEND_ELEMENT(def->routes, def->nroutes, route); VIR_APPEND_ELEMENT(def->routes, def->nroutes, route);