[PATCH v2 3/7] testSysinfo: Use more g_auto*()

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

 



Some variables defined in the function can be freed
automatically when going out of scope. This renders @result
variable and cleanup label needless.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 tests/sysinfotest.c | 22 ++++++----------------
 1 file changed, 6 insertions(+), 16 deletions(-)

diff --git a/tests/sysinfotest.c b/tests/sysinfotest.c
index a8a0d0869e..4807c5b1ba 100644
--- a/tests/sysinfotest.c
+++ b/tests/sysinfotest.c
@@ -47,34 +47,24 @@ struct testSysinfoData {
 static int
 testSysinfo(const void *data)
 {
-    int result = -1;
     const char *sysfsActualData;
-    virSysinfoDefPtr ret = NULL;
-    virBuffer buf = VIR_BUFFER_INITIALIZER;
+    g_auto(virSysinfoDefPtr) ret = NULL;
+    g_auto(virBuffer) buf = VIR_BUFFER_INITIALIZER;
     const struct testSysinfoData *testdata = data;
 
     virSysinfoSetup(testdata->decoder, testdata->sysinfo, testdata->cpuinfo);
 
     if (!testdata->expected ||
         !(ret = testdata->func()))
-        goto cleanup;
+        return -1;
 
     if (virSysinfoFormat(&buf, ret) < 0)
-        goto cleanup;
+        return -1;
 
     if (!(sysfsActualData = virBufferCurrentContent(&buf)))
-        goto cleanup;
+        return -1;
 
-    if (virTestCompareToFile(sysfsActualData, testdata->expected) < 0)
-        goto cleanup;
-
-    result = 0;
-
- cleanup:
-    virSysinfoDefFree(ret);
-    virBufferFreeAndReset(&buf);
-
-    return result;
+    return virTestCompareToFile(sysfsActualData, testdata->expected);
 }
 
 static int
-- 
2.26.2




[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