virNetworkDHCPRangeDefParseXML: Use virXMLNodeGetSubelement to find 'lease'

This also prevents a potential memleak when multiple elements would be
present.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Martin Kletzander <mkletzan@redhat.com>
This commit is contained in:
Peter Krempa 2022-12-02 11:02:58 +01:00
parent 4088b5afa3
commit 7bd0e8674c

View File

@ -453,7 +453,7 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
virNetworkDHCPRangeDef *range)
{
virSocketAddrRange *addr = &range->addr;
xmlNodePtr cur = node->children;
xmlNodePtr lease;
g_autofree char *start = NULL;
g_autofree char *end = NULL;
@ -480,15 +480,9 @@ virNetworkDHCPRangeDefParseXML(const char *networkName,
virNetworkIPDefPrefix(ipdef)) < 0)
return -1;
while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE &&
virXMLNodeNameEqual(cur, "lease")) {
if (virNetworkDHCPLeaseTimeDefParseXML(&range->lease, cur) < 0)
return -1;
}
cur = cur->next;
}
if ((lease = virXMLNodeGetSubelement(node, "lease")) &&
virNetworkDHCPLeaseTimeDefParseXML(&range->lease, lease) < 0)
return -1;
return 0;
}