mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-24 13:35:17 +00:00
virDomainNetIPInfoParseXML: Simplify cleanup
Do the XPath fetches first as they don't require cleanup and rename 'cleanup' to 'error' and take it only on failure. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
39892e6f2e
commit
eb738a75be
@ -6216,42 +6216,38 @@ virDomainNetIPInfoParseXML(const char *source,
|
|||||||
xmlXPathContextPtr ctxt,
|
xmlXPathContextPtr ctxt,
|
||||||
virNetDevIPInfo *def)
|
virNetDevIPInfo *def)
|
||||||
{
|
{
|
||||||
int ret = -1;
|
|
||||||
size_t i;
|
size_t i;
|
||||||
g_autofree xmlNodePtr *ipNodes = NULL;
|
g_autofree xmlNodePtr *ipNodes = NULL;
|
||||||
int nipNodes;
|
int nipNodes;
|
||||||
g_autofree xmlNodePtr *routeNodes = NULL;
|
g_autofree xmlNodePtr *routeNodes = NULL;
|
||||||
int nrouteNodes;
|
int nrouteNodes;
|
||||||
|
|
||||||
if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0)
|
if ((nipNodes = virXPathNodeSet("./ip", ctxt, &ipNodes)) < 0 ||
|
||||||
goto cleanup;
|
(nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
for (i = 0; i < nipNodes; i++) {
|
for (i = 0; i < nipNodes; i++) {
|
||||||
virNetDevIPAddr *ip = NULL;
|
virNetDevIPAddr *ip = NULL;
|
||||||
|
|
||||||
if (!(ip = virDomainNetIPParseXML(ipNodes[i])))
|
if (!(ip = virDomainNetIPParseXML(ipNodes[i])))
|
||||||
goto cleanup;
|
goto error;
|
||||||
|
|
||||||
VIR_APPEND_ELEMENT(def->ips, def->nips, ip);
|
VIR_APPEND_ELEMENT(def->ips, def->nips, ip);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((nrouteNodes = virXPathNodeSet("./route", ctxt, &routeNodes)) < 0)
|
|
||||||
goto cleanup;
|
|
||||||
|
|
||||||
for (i = 0; i < nrouteNodes; i++) {
|
for (i = 0; i < nrouteNodes; i++) {
|
||||||
virNetDevIPRoute *route = NULL;
|
virNetDevIPRoute *route = NULL;
|
||||||
|
|
||||||
if (!(route = virNetDevIPRouteParseXML(source, routeNodes[i], ctxt)))
|
if (!(route = virNetDevIPRouteParseXML(source, routeNodes[i], ctxt)))
|
||||||
goto cleanup;
|
goto error;
|
||||||
|
|
||||||
VIR_APPEND_ELEMENT(def->routes, def->nroutes, route);
|
VIR_APPEND_ELEMENT(def->routes, def->nroutes, route);
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = 0;
|
return 0;
|
||||||
cleanup:
|
error:
|
||||||
if (ret < 0)
|
virNetDevIPInfoClear(def);
|
||||||
virNetDevIPInfoClear(def);
|
return -1;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user