]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_monitor: Declare and use g_autoptr for qemuMonitorEventPanicInfo
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Oct 2021 07:31:22 +0000 (09:31 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Oct 2021 11:42:27 +0000 (13:42 +0200)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c

index 2508e895033a3e9b3222d85806b211c9737809a3..8214c2fd9f308b73ae0c52e21f5ca238d5a2f671 100644 (file)
@@ -194,6 +194,7 @@ struct _qemuMonitorJobInfo {
 
 char *qemuMonitorGuestPanicEventInfoFormatMsg(qemuMonitorEventPanicInfo *info);
 void qemuMonitorEventPanicInfoFree(qemuMonitorEventPanicInfo *info);
+G_DEFINE_AUTOPTR_CLEANUP_FUNC(qemuMonitorEventPanicInfo, qemuMonitorEventPanicInfoFree);
 void qemuMonitorEventRdmaGidStatusFree(qemuMonitorRdmaGidStatus *info);
 void qemuMonitorMemoryDeviceSizeChangeFree(qemuMonitorMemoryDeviceSizeChange *info);
 
index 26cbb8cedccca8b0062052132abdc9339cda768c..655d2a022f708090b3dcbf63b9c7ae51196acf3b 100644 (file)
@@ -605,9 +605,7 @@ static void qemuMonitorJSONHandleResume(qemuMonitor *mon, virJSONValue *data G_G
 static qemuMonitorEventPanicInfo *
 qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValue *data)
 {
-    qemuMonitorEventPanicInfo *ret;
-
-    ret = g_new0(qemuMonitorEventPanicInfo, 1);
+    g_autoptr(qemuMonitorEventPanicInfo) ret = g_new0(qemuMonitorEventPanicInfo, 1);
 
     ret->type = QEMU_MONITOR_EVENT_PANIC_INFO_TYPE_HYPERV;
 
@@ -618,20 +616,16 @@ qemuMonitorJSONGuestPanicExtractInfoHyperv(virJSONValue *data)
         virJSONValueObjectGetNumberUlong(data, "arg5", &ret->data.hyperv.arg5) < 0) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
                        _("malformed hyperv panic data"));
-        goto error;
+        return NULL;
     }
 
-    return ret;
-
- error:
-    qemuMonitorEventPanicInfoFree(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 static qemuMonitorEventPanicInfo *
 qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data)
 {
-    qemuMonitorEventPanicInfo *ret;
+    g_autoptr(qemuMonitorEventPanicInfo) ret = NULL;
     int core;
     unsigned long long psw_mask, psw_addr;
     const char *reason = NULL;
@@ -645,7 +639,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data)
         virJSONValueObjectGetNumberUlong(data, "psw-addr", &psw_addr) < 0 ||
         !(reason = virJSONValueObjectGetString(data, "reason"))) {
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("malformed s390 panic data"));
-        goto error;
+        return NULL;
     }
 
     ret->data.s390.core = core;
@@ -654,11 +648,7 @@ qemuMonitorJSONGuestPanicExtractInfoS390(virJSONValue *data)
 
     ret->data.s390.reason = g_strdup(reason);
 
-    return ret;
-
- error:
-    qemuMonitorEventPanicInfoFree(ret);
-    return NULL;
+    return g_steal_pointer(&ret);
 }
 
 static qemuMonitorEventPanicInfo *