]> xenbits.xensource.com Git - libvirt.git/commitdiff
testSysinfo: Use more g_auto*()
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 8 Jun 2020 09:56:45 +0000 (11:56 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 10 Jun 2020 12:00:38 +0000 (14:00 +0200)
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@redhat.com>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
tests/sysinfotest.c

index a8a0d0869e5b2340eec4925a3e12abb91ee97b95..4807c5b1ba4c1b1fd2ead5c5a2998e6a62b24bba 100644 (file)
@@ -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