[libvirt] [PATCH v2 2/4] conf: Use only one temporary string in virDomainDiskSourceParse

Peter Krempa pkrempa at redhat.com
Fri Apr 28 11:10:25 UTC 2017


---
 src/conf/domain_conf.c | 13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 5a736c853..c40a5a7a6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7526,7 +7526,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
                          virStorageSourcePtr src)
 {
     int ret = -1;
-    char *protocol = NULL;
+    char *tmp = NULL;
     xmlNodePtr saveNode = ctxt->node;

     ctxt->node = node;
@@ -7542,17 +7542,18 @@ virDomainDiskSourceParse(xmlNodePtr node,
         src->path = virXMLPropString(node, "dir");
         break;
     case VIR_STORAGE_TYPE_NETWORK:
-        if (!(protocol = virXMLPropString(node, "protocol"))) {
+        if (!(tmp = virXMLPropString(node, "protocol"))) {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("missing network source protocol type"));
             goto cleanup;
         }

-        if ((src->protocol = virStorageNetProtocolTypeFromString(protocol)) <= 0) {
+        if ((src->protocol = virStorageNetProtocolTypeFromString(tmp)) <= 0) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown protocol type '%s'"), protocol);
+                           _("unknown protocol type '%s'"), tmp);
             goto cleanup;
         }
+        VIR_FREE(tmp);

         if (!(src->path = virXMLPropString(node, "name")) &&
             src->protocol != VIR_STORAGE_NET_PROTOCOL_NBD) {
@@ -7565,7 +7566,6 @@ virDomainDiskSourceParse(xmlNodePtr node,
          * as a part of the path. This is hard to work with when dealing with
          * relative names. Split out the volume into a separate variable */
         if (src->path && src->protocol == VIR_STORAGE_NET_PROTOCOL_GLUSTER) {
-            char *tmp;
             if (!(tmp = strchr(src->path, '/')) ||
                 tmp == src->path) {
                 virReportError(VIR_ERR_XML_ERROR,
@@ -7580,6 +7580,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
                 goto cleanup;

             tmp[0] = '\0';
+            tmp = NULL;
         }

         /* snapshot currently works only for remote disks */
@@ -7612,7 +7613,7 @@ virDomainDiskSourceParse(xmlNodePtr node,
     ret = 0;

  cleanup:
-    VIR_FREE(protocol);
+    VIR_FREE(tmp);
     ctxt->node = saveNode;
     return ret;
 }
-- 
2.12.2




More information about the libvir-list mailing list