]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu_monitor_json: Use g_autoptr() for virCPUData
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Oct 2021 07:57:39 +0000 (09:57 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Oct 2021 11:42:32 +0000 (13:42 +0200)
We have g_autoptr() for virCPUData struct defined already. Let's
use it in qemu_monitor_json.c and drop explicit free calls.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Tim Wiederhake <twiederh@redhat.com>
src/qemu/qemu_monitor_json.c

index 655d2a022f708090b3dcbf63b9c7ae51196acf3b..3d89afa6c64146a5c6d4b9009df42b767c815b90 100644 (file)
@@ -7288,7 +7288,7 @@ qemuMonitorJSONParseCPUx86FeatureWord(virJSONValue *data,
 static virCPUData *
 qemuMonitorJSONParseCPUx86Features(virJSONValue *data)
 {
-    virCPUData *cpudata = NULL;
+    g_autoptr(virCPUData) cpudata = NULL;
     virCPUx86DataItem item = { 0 };
     size_t i;
 
@@ -7303,10 +7303,9 @@ qemuMonitorJSONParseCPUx86Features(virJSONValue *data)
             goto error;
     }
 
-    return cpudata;
+    return g_steal_pointer(&cpudata);
 
  error:
-    virCPUDataFree(cpudata);
     return NULL;
 }
 
@@ -7418,8 +7417,8 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon,
                               virCPUData **data,
                               virCPUData **disabled)
 {
-    virCPUData *cpuEnabled = NULL;
-    virCPUData *cpuDisabled = NULL;
+    g_autoptr(virCPUData) cpuEnabled = NULL;
+    g_autoptr(virCPUData) cpuDisabled = NULL;
     int rc;
 
     if ((rc = qemuMonitorJSONCheckCPUx86(mon)) < 0)
@@ -7436,14 +7435,12 @@ qemuMonitorJSONGetGuestCPUx86(qemuMonitor *mon,
                                      &cpuDisabled) < 0)
         goto error;
 
-    *data = cpuEnabled;
+    *data = g_steal_pointer(&cpuEnabled);
     if (disabled)
-        *disabled = cpuDisabled;
+        *disabled = g_steal_pointer(&cpuDisabled);
     return 0;
 
  error:
-    virCPUDataFree(cpuEnabled);
-    virCPUDataFree(cpuDisabled);
     return -1;
 }
 
@@ -7554,8 +7551,8 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon,
                            virCPUData **enabled,
                            virCPUData **disabled)
 {
-    virCPUData *cpuEnabled = NULL;
-    virCPUData *cpuDisabled = NULL;
+    g_autoptr(virCPUData) cpuEnabled = NULL;
+    g_autoptr(virCPUData) cpuDisabled = NULL;
     int ret = -1;
 
     if (!(cpuEnabled = virCPUDataNew(arch)) ||
@@ -7576,8 +7573,6 @@ qemuMonitorJSONGetGuestCPU(qemuMonitor *mon,
     ret = 0;
 
  cleanup:
-    virCPUDataFree(cpuEnabled);
-    virCPUDataFree(cpuDisabled);
     return ret;
 }