This also prevents a potential memleak when multiple elements would be present. Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx> --- 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 e33925f857..5d1f0e5203 100644 --- a/src/conf/network_conf.c +++ b/src/conf/network_conf.c @@ -501,7 +501,7 @@ virNetworkDHCPHostDefParseXML(const char *networkName, g_autofree char *id = NULL; virMacAddr addr; virSocketAddr inaddr; - xmlNodePtr cur = node->children; + xmlNodePtr lease; mac = virXMLPropString(node, "mac"); if (mac != NULL) { @@ -593,15 +593,9 @@ virNetworkDHCPHostDefParseXML(const char *networkName, } } - while (cur != NULL) { - if (cur->type == XML_ELEMENT_NODE && - virXMLNodeNameEqual(cur, "lease")) { - - if (virNetworkDHCPLeaseTimeDefParseXML(&host->lease, cur) < 0) - return -1; - } - cur = cur->next; - } + if ((lease = virXMLNodeGetSubelement(node, "lease")) && + virNetworkDHCPLeaseTimeDefParseXML(&host->lease, lease) < 0) + return -1; host->mac = g_steal_pointer(&mac); host->id = g_steal_pointer(&id); -- 2.39.1