From 7bd0e8674cedde9a3456d8fa05e80dd69079611b Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Fri, 2 Dec 2022 11:02:58 +0100 Subject: [PATCH] virNetworkDHCPRangeDefParseXML: Use virXMLNodeGetSubelement to find 'lease' MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This also prevents a potential memleak when multiple elements would be present. Signed-off-by: Peter Krempa Reviewed-by: Ján Tomko Reviewed-by: Martin Kletzander --- src/conf/network_conf.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c index b98ae6aa3f..e33925f857 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -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; }