[libvirt PATCH 8/9] ch: use g_auto in virCHMonitorBuildVMJson

Ján Tomko jtomko at redhat.com
Wed Sep 22 20:55:34 UTC 2021


Signed-off-by: Ján Tomko <jtomko at redhat.com>
---
 src/ch/ch_monitor.c | 25 ++++++++++---------------
 1 file changed, 10 insertions(+), 15 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index aa27eea304..3504c21f9d 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -354,41 +354,36 @@ virCHMonitorBuildNetsJson(virJSONValue *content, virDomainDef *vmdef)
 static int
 virCHMonitorBuildVMJson(virDomainDef *vmdef, char **jsonstr)
 {
-    virJSONValue *content = virJSONValueNewObject();
-    int ret = -1;
+    g_autoptr(virJSONValue) content = virJSONValueNewObject();
 
     if (vmdef == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("VM is not defined"));
-        goto cleanup;
+        return -1;
     }
 
     if (virCHMonitorBuildPTYJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCHMonitorBuildCPUJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCHMonitorBuildMemoryJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCHMonitorBuildKernelRelatedJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCHMonitorBuildDisksJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (virCHMonitorBuildNetsJson(content, vmdef) < 0)
-        goto cleanup;
+        return -1;
 
     if (!(*jsonstr = virJSONValueToString(content, false)))
-        goto cleanup;
+        return -1;
 
-    ret = 0;
-
- cleanup:
-    virJSONValueFree(content);
-    return ret;
+    return 0;
 }
 
 static int
-- 
2.31.1




More information about the libvir-list mailing list