提交 03b6bdca 编写于 作者: L Laine Stump

conf: reorganize virNetworkDHCPDefParseXML

This makes the range and static host array management in
virNetworkDHCPDefParseXML() more similar to what is done in
virNetworkDefUpdateIPDHCPRange() and virNetworkDefUpdateIPDHCPHost() -
they use VIR_APPEND_ELEMENT rather than a combination of
VIR_REALLOC_N() and separate incrementing of the array size.

The one functional change here is that a memory leak of the contents
of the last (unsuccessful) virNetworkDHCPHostDef was previously leaked
in certain failure conditions, but it is now properly cleaned up.
上级 f86c45ca
...@@ -1023,33 +1023,32 @@ virNetworkDHCPDefParseXML(const char *networkName, ...@@ -1023,33 +1023,32 @@ virNetworkDHCPDefParseXML(const char *networkName,
xmlNodePtr node, xmlNodePtr node,
virNetworkIpDefPtr def) virNetworkIpDefPtr def)
{ {
int ret = -1;
xmlNodePtr cur; xmlNodePtr cur;
virSocketAddrRange range;
virNetworkDHCPHostDef host;
memset(&range, 0, sizeof(range));
memset(&host, 0, sizeof(host));
cur = node->children; cur = node->children;
while (cur != NULL) { while (cur != NULL) {
if (cur->type == XML_ELEMENT_NODE && if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "range")) { xmlStrEqual(cur->name, BAD_CAST "range")) {
if (VIR_REALLOC_N(def->ranges, def->nranges + 1) < 0) if (virSocketAddrRangeParseXML(networkName, def, cur, &range) < 0)
return -1; goto cleanup;
if (virSocketAddrRangeParseXML(networkName, def, cur, if (VIR_APPEND_ELEMENT(def->ranges, def->nranges, range) < 0)
&def->ranges[def->nranges]) < 0) { goto cleanup;
return -1;
}
def->nranges++;
} else if (cur->type == XML_ELEMENT_NODE && } else if (cur->type == XML_ELEMENT_NODE &&
xmlStrEqual(cur->name, BAD_CAST "host")) { xmlStrEqual(cur->name, BAD_CAST "host")) {
if (VIR_REALLOC_N(def->hosts, def->nhosts + 1) < 0)
return -1;
if (virNetworkDHCPHostDefParseXML(networkName, def, cur, if (virNetworkDHCPHostDefParseXML(networkName, def, cur,
&def->hosts[def->nhosts], &host, false) < 0)
false) < 0) { goto cleanup;
return -1; if (VIR_APPEND_ELEMENT(def->hosts, def->nhosts, host) < 0)
} goto cleanup;
def->nhosts++;
} else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET) && } else if (VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET) &&
cur->type == XML_ELEMENT_NODE && cur->type == XML_ELEMENT_NODE &&
...@@ -1069,7 +1068,7 @@ virNetworkDHCPDefParseXML(const char *networkName, ...@@ -1069,7 +1068,7 @@ virNetworkDHCPDefParseXML(const char *networkName,
virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) { virSocketAddrParse(&inaddr, server, AF_UNSPEC) < 0) {
VIR_FREE(file); VIR_FREE(file);
VIR_FREE(server); VIR_FREE(server);
return -1; goto cleanup;
} }
def->bootfile = file; def->bootfile = file;
...@@ -1080,7 +1079,10 @@ virNetworkDHCPDefParseXML(const char *networkName, ...@@ -1080,7 +1079,10 @@ virNetworkDHCPDefParseXML(const char *networkName,
cur = cur->next; cur = cur->next;
} }
return 0; ret = 0;
cleanup:
virNetworkDHCPHostDefClear(&host);
return ret;
} }
static int static int
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册