]> xenbits.xensource.com Git - libvirt.git/commitdiff
tests: Use g_autofree in testParseVMXFileName
authorMartin Kletzander <mkletzan@redhat.com>
Mon, 21 Dec 2020 15:56:25 +0000 (16:56 +0100)
committerMartin Kletzander <mkletzan@redhat.com>
Wed, 6 Jan 2021 01:05:10 +0000 (02:05 +0100)
There's only one variable to clean-up, others are just tokens inside that
variable, but it is nicer anyway.  Positive returns have not been converted
because the function will change soon and it would not make much sense.

Signed-off-by: Martin Kletzander <mkletzan@redhat.com>
tests/vmx2xmltest.c

index 376116bb750a54c65d90596bc316ac54849cc55e..8cc227bbedfc61a32a8a207b50c57d27009a5f5d 100644 (file)
@@ -130,7 +130,7 @@ testCompareHelper(const void *data)
 static char *
 testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
 {
-    char *copyOfFileName = NULL;
+    g_autofree char *copyOfFileName = NULL;
     char *tmp = NULL;
     char *saveptr = NULL;
     char *datastoreName = NULL;
@@ -145,7 +145,7 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
         if ((tmp = STRSKIP(copyOfFileName, "/vmfs/volumes/")) == NULL ||
             (datastoreName = strtok_r(tmp, "/", &saveptr)) == NULL ||
             (directoryAndFileName = strtok_r(NULL, "", &saveptr)) == NULL) {
-            goto cleanup;
+            return NULL;
         }
 
         src = g_strdup_printf("[%s] %s", datastoreName, directoryAndFileName);
@@ -154,15 +154,12 @@ testParseVMXFileName(const char *fileName, void *opaque G_GNUC_UNUSED)
         src = g_strdup(fileName);
     } else if (strchr(fileName, '/') != NULL) {
         /* Found relative path, this is not supported */
-        src = NULL;
+        return NULL;
     } else {
         /* Found single file name referencing a file inside a datastore */
         src = g_strdup_printf("[datastore] directory/%s", fileName);
     }
 
- cleanup:
-    VIR_FREE(copyOfFileName);
-
     return src;
 }