[libvirt PATCH 1/6] tests: esxutils: refactor testParseDatastorePath

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

 



Reduce variable scope to match their lifetime,
use g_auto and remove now pointless labels in favor
of direct returns.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/esxutilstest.c | 30 ++++++++----------------------
 1 file changed, 8 insertions(+), 22 deletions(-)

diff --git a/tests/esxutilstest.c b/tests/esxutilstest.c
index 2e2020006e..bfb35fa356 100644
--- a/tests/esxutilstest.c
+++ b/tests/esxutilstest.c
@@ -35,21 +35,17 @@ static struct testPath paths[] = {
 static int
 testParseDatastorePath(const void *data G_GNUC_UNUSED)
 {
-    int result = 0;
     size_t i;
-    char *datastoreName = NULL;
-    char *directoryName = NULL;
-    char *directoryAndFileName = NULL;
 
     for (i = 0; i < G_N_ELEMENTS(paths); ++i) {
-        VIR_FREE(datastoreName);
-        VIR_FREE(directoryName);
-        VIR_FREE(directoryAndFileName);
+        g_autofree char *datastoreName = NULL;
+        g_autofree char *directoryName = NULL;
+        g_autofree char *directoryAndFileName = NULL;
 
         if (esxUtil_ParseDatastorePath
              (paths[i].datastorePath, &datastoreName, &directoryName,
               &directoryAndFileName) != paths[i].result) {
-            goto failure;
+            return -1;
         }
 
         if (paths[i].result < 0)
@@ -57,32 +53,22 @@ testParseDatastorePath(const void *data G_GNUC_UNUSED)
 
         if (STRNEQ(paths[i].datastoreName, datastoreName)) {
             virTestDifference(stderr, paths[i].datastoreName, datastoreName);
-            goto failure;
+            return -1;
         }
 
         if (STRNEQ(paths[i].directoryName, directoryName)) {
             virTestDifference(stderr, paths[i].directoryName, directoryName);
-            goto failure;
+            return -1;
         }
 
         if (STRNEQ(paths[i].directoryAndFileName, directoryAndFileName)) {
             virTestDifference(stderr, paths[i].directoryAndFileName,
                               directoryAndFileName);
-            goto failure;
+            return -1;
         }
     }
 
- cleanup:
-    VIR_FREE(datastoreName);
-    VIR_FREE(directoryName);
-    VIR_FREE(directoryAndFileName);
-
-    return result;
-
- failure:
-    result = -1;
-
-    goto cleanup;
+    return 0;
 }
 
 
-- 
2.31.1




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux