]> xenbits.xensource.com Git - libvirt.git/commitdiff
util: Remove need for extra VIR_FREE's in virGetFCHostNameByWWN
authorJohn Ferlan <jferlan@redhat.com>
Fri, 18 Nov 2016 13:55:35 +0000 (08:55 -0500)
committerJohn Ferlan <jferlan@redhat.com>
Wed, 4 Jan 2017 22:09:59 +0000 (17:09 -0500)
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@redhat.com>
src/util/virutil.c

index 933d5b06b4a31c273d1ae4ed00ee4293a9ef918d..701c382a5dde46812ecb187b9c71548f77d1e815 100644 (file)
@@ -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;