From 1d0fde7ee137d2a80c937db1037cbc5fd2e2cde5 Mon Sep 17 00:00:00 2001 From: John Ferlan Date: Fri, 18 Nov 2016 08:55:35 -0500 Subject: [PATCH] util: Remove need for extra VIR_FREE's in virGetFCHostNameByWWN 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 --- 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 933d5b06b4..701c382a5d 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; -- GitLab