]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: use g_auto in virCHMonitorBuildDiskJson
authorJán Tomko <jtomko@redhat.com>
Wed, 22 Sep 2021 20:48:58 +0000 (22:48 +0200)
committerJán Tomko <jtomko@redhat.com>
Thu, 23 Sep 2021 13:32:00 +0000 (15:32 +0200)
Signed-off-by: Ján Tomko <jtomko@redhat.com>
Reviewed-by: Laine Stump <laine@redhat.com>
src/ch/ch_monitor.c

index 876a553f74223802afcfa45389ecc15f0127f1f6..3ef2c3fb15d4f3bb09d71537d308e24c84fbce7d 100644 (file)
@@ -177,31 +177,31 @@ virCHMonitorBuildMemoryJson(virJSONValue *content, virDomainDef *vmdef)
 static int
 virCHMonitorBuildDiskJson(virJSONValue *disks, virDomainDiskDef *diskdef)
 {
-    virJSONValue *disk = virJSONValueNewObject();
+    g_autoptr(virJSONValue) disk = virJSONValueNewObject();
 
     if (!diskdef->src)
-        goto cleanup;
+        return -1;
 
     switch (diskdef->src->type) {
     case VIR_STORAGE_TYPE_FILE:
         if (!diskdef->src->path) {
             virReportError(VIR_ERR_INVALID_ARG, "%s",
                            _("Missing disk file path in domain"));
-            goto cleanup;
+            return -1;
         }
         if (diskdef->bus != VIR_DOMAIN_DISK_BUS_VIRTIO) {
             virReportError(VIR_ERR_INVALID_ARG,
                            _("Only virtio bus types are supported for '%s'"), diskdef->src->path);
-            goto cleanup;
+            return -1;
         }
         if (virJSONValueObjectAppendString(disk, "path", diskdef->src->path) < 0)
-            goto cleanup;
+            return -1;
         if (diskdef->src->readonly) {
             if (virJSONValueObjectAppendBoolean(disk, "readonly", true) < 0)
-                goto cleanup;
+                return -1;
         }
         if (virJSONValueArrayAppend(disks, &disk) < 0)
-            goto cleanup;
+            return -1;
 
         break;
     case VIR_STORAGE_TYPE_NONE:
@@ -213,14 +213,10 @@ virCHMonitorBuildDiskJson(virJSONValue *disks, virDomainDiskDef *diskdef)
     case VIR_STORAGE_TYPE_VHOST_USER:
     default:
         virReportEnumRangeError(virStorageType, diskdef->src->type);
-        goto cleanup;
+        return -1;
     }
 
     return 0;
-
- cleanup:
-    virJSONValueFree(disk);
-    return -1;
 }
 
 static int