[libvirt] [PATCH 09/11] util: Remove need for extra VIR_FREE's in virGetFCHostNameByWWN

John Ferlan jferlan at redhat.com
Fri Nov 18 14:26:35 UTC 2016


Rather than extraneous VIR_FREE's depending on where we are in the code,
move them to the top of the loop and in the cleanup path.

Signed-off-by: John Ferlan <jferlan at redhat.com>
---
 src/util/virutil.c | 27 +++++++++------------------
 1 file changed, 9 insertions(+), 18 deletions(-)

diff --git a/src/util/virutil.c b/src/util/virutil.c
index 844c947..a135819 100644
--- a/src/util/virutil.c
+++ b/src/util/virutil.c
@@ -2205,43 +2205,34 @@ virGetFCHostNameByWWN(const char *sysfs_prefix,
     } while (0)
 
     while (virDirRead(dir, &entry, prefix) > 0) {
+        VIR_FREE(wwnn_buf);
+        VIR_FREE(wwnn_path);
+        VIR_FREE(wwpn_buf);
+        VIR_FREE(wwpn_path);
+
         if (virAsprintf(&wwnn_path, "%s/%s/node_name", prefix,
                         entry->d_name) < 0)
             goto cleanup;
 
-        if (!virFileExists(wwnn_path)) {
-            VIR_FREE(wwnn_path);
+        if (!virFileExists(wwnn_path))
             continue;
-        }
 
         READ_WWN(wwnn_path, wwnn_buf);
 
-        if (STRNEQ(wwnn, p)) {
-            VIR_FREE(wwnn_buf);
-            VIR_FREE(wwnn_path);
+        if (STRNEQ(wwnn, p))
             continue;
-        }
 
         if (virAsprintf(&wwpn_path, "%s/%s/port_name", prefix,
                         entry->d_name) < 0)
             goto cleanup;
 
-        if (!virFileExists(wwpn_path)) {
-            VIR_FREE(wwnn_buf);
-            VIR_FREE(wwnn_path);
-            VIR_FREE(wwpn_path);
+        if (!virFileExists(wwpn_path))
             continue;
-        }
 
         READ_WWN(wwpn_path, wwpn_buf);
 
-        if (STRNEQ(wwpn, p)) {
-            VIR_FREE(wwnn_path);
-            VIR_FREE(wwpn_path);
-            VIR_FREE(wwnn_buf);
-            VIR_FREE(wwpn_buf);
+        if (STRNEQ(wwpn, p))
             continue;
-        }
 
         ignore_value(VIR_STRDUP(ret, entry->d_name));
         break;
-- 
2.7.4




More information about the libvir-list mailing list