]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: use g_auto in virCHMonitorBuildKernelRelatedJson
authorWilliam Douglas <william.douglas@intel.com>
Fri, 1 Oct 2021 18:12:36 +0000 (11:12 -0700)
committerLaine Stump <laine@redhat.com>
Tue, 5 Oct 2021 04:07:23 +0000 (00:07 -0400)
Signed-off-by: William Douglas <william.douglas@intel.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/ch/ch_monitor.c

index 841a2b6c8ec2ea993b86eaf7ca3e9432ba881666..a919b93b5026bee57d2826464cfb0d2ca79838ac 100644 (file)
@@ -112,43 +112,36 @@ virCHMonitorBuildPTYJson(virJSONValue *content, virDomainDef *vmdef)
 static int
 virCHMonitorBuildKernelRelatedJson(virJSONValue *content, virDomainDef *vmdef)
 {
-    virJSONValue *kernel = virJSONValueNewObject();
-    virJSONValue *cmdline = virJSONValueNewObject();
-    virJSONValue *initramfs = virJSONValueNewObject();
+    g_autoptr(virJSONValue) kernel = virJSONValueNewObject();
+    g_autoptr(virJSONValue) cmdline = virJSONValueNewObject();
+    g_autoptr(virJSONValue) initramfs = virJSONValueNewObject();
 
     if (vmdef->os.kernel == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("Kernel image path in this domain is not defined"));
-        goto cleanup;
+        return -1;
     } else {
         if (virJSONValueObjectAppendString(kernel, "path", vmdef->os.kernel) < 0)
-            goto cleanup;
+            return -1;
         if (virJSONValueObjectAppend(content, "kernel", &kernel) < 0)
-            goto cleanup;
+            return -1;
     }
 
     if (vmdef->os.cmdline) {
         if (virJSONValueObjectAppendString(cmdline, "args", vmdef->os.cmdline) < 0)
-            goto cleanup;
+            return -1;
         if (virJSONValueObjectAppend(content, "cmdline", &cmdline) < 0)
-            goto cleanup;
+            return -1;
     }
 
     if (vmdef->os.initrd != NULL) {
         if (virJSONValueObjectAppendString(initramfs, "path", vmdef->os.initrd) < 0)
-            goto cleanup;
+            return -1;
         if (virJSONValueObjectAppend(content, "initramfs", &initramfs) < 0)
-            goto cleanup;
+            return -1;
     }
 
     return 0;
-
- cleanup:
-    virJSONValueFree(kernel);
-    virJSONValueFree(cmdline);
-    virJSONValueFree(initramfs);
-
-    return -1;
 }
 
 static int