[libvirt PATCH 1/2] tests: use g_auto in testQemuGetCaps

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

 



Refactor testQemuGetCaps to use g_auto for cleanup,
remove the error label and use g_steal_pointer for
the successful return path.

Signed-off-by: Ján Tomko <jtomko@xxxxxxxxxx>
---
 tests/qemucaps2xmltest.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/tests/qemucaps2xmltest.c b/tests/qemucaps2xmltest.c
index ce1116b792..78a2148e1a 100644
--- a/tests/qemucaps2xmltest.c
+++ b/tests/qemucaps2xmltest.c
@@ -50,22 +50,22 @@ testQemuDataInit(testQemuData *data)
 static virQEMUCaps *
 testQemuGetCaps(char *caps)
 {
-    virQEMUCaps *qemuCaps = NULL;
+    g_autoptr(virQEMUCaps) qemuCaps = NULL;
     g_autoptr(xmlDoc) xml = NULL;
     g_autoptr(xmlXPathContext) ctxt = NULL;
     ssize_t i, n;
     g_autofree xmlNodePtr *nodes = NULL;
 
     if (!(xml = virXMLParseStringCtxt(caps, "(test caps)", &ctxt)))
-        goto error;
+        return NULL;
 
     if ((n = virXPathNodeSet("/qemuCaps/flag", ctxt, &nodes)) < 0) {
         fprintf(stderr, "failed to parse qemu capabilities flags");
-        goto error;
+        return NULL;
     }
 
     if (!(qemuCaps = virQEMUCapsNew()))
-        goto error;
+        return NULL;
 
     for (i = 0; i < n; i++) {
         g_autofree char *str = virXMLPropString(nodes[i], "name");
@@ -73,17 +73,13 @@ testQemuGetCaps(char *caps)
             int flag = virQEMUCapsTypeFromString(str);
             if (flag < 0) {
                 fprintf(stderr, "Unknown qemu capabilities flag %s", str);
-                goto error;
+                return NULL;
             }
             virQEMUCapsSet(qemuCaps, flag);
         }
     }
 
-    return qemuCaps;
-
- error:
-    virObjectUnref(qemuCaps);
-    return NULL;
+    return g_steal_pointer(&qemuCaps);
 }
 
 static virCaps *
-- 
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