[PATCH 06/14] tests: storage: Refactor cleanup in testBackingParse

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

 



Automatically clean the temporary buffer and get rid of the cleanup
label.

Signed-off-by: Peter Krempa <pkrempa@xxxxxxxxxx>
---
 tests/virstoragetest.c | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/tests/virstoragetest.c b/tests/virstoragetest.c
index ef16b3c6e0..1c7ba466f1 100644
--- a/tests/virstoragetest.c
+++ b/tests/virstoragetest.c
@@ -609,28 +609,27 @@ static int
 testBackingParse(const void *args)
 {
     const struct testBackingParseData *data = args;
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
-    int ret = -1;
+    VIR_AUTOCLEAN(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     VIR_AUTOFREE(char *) xml = NULL;
     VIR_AUTOUNREF(virStorageSourcePtr) src = NULL;

     if (!(src = virStorageSourceNewFromBackingAbsolute(data->backing))) {
         if (!data->expect)
-            ret = 0;
-
-        goto cleanup;
+            return 0;
+        else
+            return -1;
     }

     if (src && !data->expect) {
         fprintf(stderr, "parsing of backing store string '%s' should "
                         "have failed\n", data->backing);
-        goto cleanup;
+        return -1;
     }

     if (virDomainDiskSourceFormat(&buf, src, "source", 0, false, 0, NULL) < 0 ||
         !(xml = virBufferContentAndReset(&buf))) {
         fprintf(stderr, "failed to format disk source xml\n");
-        goto cleanup;
+        return -1;
     }

     if (STRNEQ(xml, data->expect)) {
@@ -638,15 +637,10 @@ testBackingParse(const void *args)
                         "expected storage source xml:\n%s\n"
                         "actual storage source xml:\n%s\n",
                         data->backing, data->expect, xml);
-        goto cleanup;
+        return -1;
     }

-    ret = 0;
-
- cleanup:
-    virBufferFreeAndReset(&buf);
-
-    return ret;
+    return 0;
 }


-- 
2.21.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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