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

[libvirt] [PATCH 12/17] conf: move UDP chardev source parsing to separate function



The extra check whether (connect|bind)(Host|Service) was set is
required because for UDP chardev there can be two source elements.
Without the check there could be a memory leak.

Signed-off-by: Pavel Hrdina <phrdina redhat com>
---
 src/conf/domain_conf.c | 56 ++++++++++++++++++++++----------------------------
 1 file changed, 25 insertions(+), 31 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 023d86cec5..d8a195a141 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10966,6 +10966,29 @@ virDomainChrSourceDefParseTCP(virDomainChrSourceDefPtr def,
 
 
 static int
+virDomainChrSourceDefParseUDP(virDomainChrSourceDefPtr def,
+                              xmlNodePtr source)
+{
+    int mode;
+
+    if ((mode = virDomainChrSourceDefParseMode(source)) < 0)
+        return -1;
+
+    if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT &&
+        !def->data.udp.connectHost && !def->data.udp.connectService) {
+        def->data.udp.connectHost = virXMLPropString(source, "host");
+        def->data.udp.connectService = virXMLPropString(source, "service");
+    } else if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND &&
+               !def->data.udp.bindHost && !def->data.udp.bindService) {
+        def->data.udp.bindHost = virXMLPropString(source, "host");
+        def->data.udp.bindService = virXMLPropString(source, "service");
+    }
+
+    return 0;
+}
+
+
+static int
 virDomainChrSourceDefParseProtocol(virDomainChrSourceDefPtr def,
                                    xmlNodePtr protocol)
 {
@@ -11028,10 +11051,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
 {
     int ret = -1;
     int mode = VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT;
-    char *bindHost = NULL;
-    char *bindService = NULL;
-    char *connectHost = NULL;
-    char *connectService = NULL;
     char *path = NULL;
     char *channel = NULL;
     char *master = NULL;
@@ -11083,19 +11102,8 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
                 break;
 
             case VIR_DOMAIN_CHR_TYPE_UDP:
-                if ((mode = virDomainChrSourceDefParseMode(cur)) < 0)
+                if (virDomainChrSourceDefParseUDP(def, cur) < 0)
                     goto error;
-                if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_CONNECT) {
-                    if (!connectHost)
-                        connectHost = virXMLPropString(cur, "host");
-                    if (!connectService)
-                        connectService = virXMLPropString(cur, "service");
-                } else if (mode == VIR_DOMAIN_CHR_SOURCE_MODE_BIND) {
-                    if (!bindHost)
-                        bindHost = virXMLPropString(cur, "host");
-                    if (!bindService)
-                        bindService = virXMLPropString(cur, "service");
-                }
                 break;
 
             case VIR_DOMAIN_CHR_TYPE_TCP:
@@ -11224,21 +11232,11 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
         break;
 
     case VIR_DOMAIN_CHR_TYPE_UDP:
-        if (!connectService) {
+        if (!def->data.udp.connectService) {
             virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                            _("Missing source service attribute for char device"));
             goto error;
         }
-
-        def->data.udp.connectHost = connectHost;
-        connectHost = NULL;
-        def->data.udp.connectService = connectService;
-        connectService = NULL;
-
-        def->data.udp.bindHost = bindHost;
-        bindHost = NULL;
-        def->data.udp.bindService = bindService;
-        bindService = NULL;
         break;
 
     case VIR_DOMAIN_CHR_TYPE_UNIX:
@@ -11276,10 +11274,6 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDefPtr def,
 
     ret = 0;
  cleanup:
-    VIR_FREE(bindHost);
-    VIR_FREE(bindService);
-    VIR_FREE(connectHost);
-    VIR_FREE(connectService);
     VIR_FREE(path);
     VIR_FREE(channel);
     VIR_FREE(append);
-- 
2.13.5


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