]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
tests: esxutils: refactor testParseDatastorePath
authorJán Tomko <jtomko@redhat.com>
Fri, 3 Sep 2021 18:15:46 +0000 (20:15 +0200)
committerJán Tomko <jtomko@redhat.com>
Wed, 8 Sep 2021 13:31:01 +0000 (15:31 +0200)
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@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
tests/esxutilstest.c

index 2e2020006e6bd4de130a590260f1ac90da7c5911..bfb35fa356a1f168abee1338870aefd4177776c9 100644 (file)
@@ -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;
 }