Re: [PATCH v3 1/3] conf: Make virNetworkIPDefParseXML a little bit saner

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 12/16/2016 01:09 PM, Jiri Denemark wrote:
Iterating over all child nodes when we only support one instance of each
child is pretty weired. And it would even cause memory leaks if more

s/weired/weird/

ACK sustained.

than one <tftp> element was specified.

Signed-off-by: Jiri Denemark <jdenemar@xxxxxxxxxx>
---

Notes:
     ACKed in v2

  src/conf/network_conf.c | 36 ++++++++++++++----------------------
  1 file changed, 14 insertions(+), 22 deletions(-)

diff --git a/src/conf/network_conf.c b/src/conf/network_conf.c
index aabf315c9..b6849ceab 100644
--- a/src/conf/network_conf.c
+++ b/src/conf/network_conf.c
@@ -1501,7 +1501,8 @@ virNetworkIPDefParseXML(const char *networkName,
       * On failure clear it out, but don't free it.
       */
- xmlNodePtr cur, save;
+    xmlNodePtr save;
+    xmlNodePtr dhcp;
      char *address = NULL, *netmask = NULL;
      unsigned long prefix = 0;
      int prefixRc;
@@ -1603,29 +1604,20 @@ virNetworkIPDefParseXML(const char *networkName,
          goto cleanup;
      }
- cur = node->children;
-    while (cur != NULL) {
-        if (cur->type == XML_ELEMENT_NODE &&
-            xmlStrEqual(cur->name, BAD_CAST "dhcp")) {
-            if (virNetworkDHCPDefParseXML(networkName, cur, def) < 0)
-                goto cleanup;
-        } else if (cur->type == XML_ELEMENT_NODE &&
-                   xmlStrEqual(cur->name, BAD_CAST "tftp")) {
-            char *root;
+    if ((dhcp = virXPathNode("./dhcp[1]", ctxt)) &&
+        virNetworkDHCPDefParseXML(networkName, dhcp, def) < 0)
+        goto cleanup;
- if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
-                virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                               _("Unsupported <tftp> element in an IPv6 element in network '%s'"),
-                               networkName);
-                goto cleanup;
-            }
-            if (!(root = virXMLPropString(cur, "root"))) {
-                cur = cur->next;
-                continue;
-            }
-            def->tftproot = (char *)root;
+    if (virXPathNode("./tftp[1]", ctxt)) {
+        if (!VIR_SOCKET_ADDR_IS_FAMILY(&def->address, AF_INET)) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("Unsupported <tftp> element in an IPv6 element "
+                             "in network '%s'"),
+                           networkName);
+            goto cleanup;
          }
-        cur = cur->next;
+
+        def->tftproot = virXPathString("string(./tftp[1]/@root)", ctxt);
      }
result = 0;


--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]
  Powered by Linux