]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemuMonitorJSONQueryRxFilterParse: Set *filter only on success
authorMichal Privoznik <mprivozn@redhat.com>
Fri, 22 Oct 2021 05:17:03 +0000 (07:17 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 25 Oct 2021 11:42:22 +0000 (13:42 +0200)
The qemuMonitorJSONQueryRxFilterParse() function is called to
parse the output of 'query-rx-filter' and store results into
passed virNetDevRxFilter structure. However, it is doing so in a
bit clumsy way - the return pointer is set in all cases (i.e.
even in case of error) and thus the cleanup label is more
complicated than it needs to be. With a help of g_autoptr() and
g_steal_pointer() the return pointer can be set only in case of
success - which is what callers expect anyway.

The same applies to qemuMonitorJSONQueryRxFilter().

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

index bcbb4e59abf8cb44147ced460d073665b8f84ecc..26cbb8cedccca8b0062052132abdc9339cda768c 100644 (file)
@@ -4035,7 +4035,7 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg,
     virJSONValue *element;
     size_t nTable;
     size_t i;
-    virNetDevRxFilter *fil = virNetDevRxFilterNew();
+    g_autoptr(virNetDevRxFilter) fil = virNetDevRxFilterNew();
 
     if (!fil)
         goto cleanup;
@@ -4187,13 +4187,9 @@ qemuMonitorJSONQueryRxFilterParse(virJSONValue *msg,
     }
     fil->vlan.nTable = nTable;
 
+    *filter = g_steal_pointer(&fil);
     ret = 0;
  cleanup:
-    if (ret < 0) {
-        virNetDevRxFilterFree(fil);
-        fil = NULL;
-    }
-    *filter = fil;
     return ret;
 }
 
@@ -4222,10 +4218,6 @@ qemuMonitorJSONQueryRxFilter(qemuMonitor *mon, const char *alias,
 
     ret = 0;
  cleanup:
-    if (ret < 0) {
-        virNetDevRxFilterFree(*filter);
-        *filter = NULL;
-    }
     virJSONValueFree(cmd);
     virJSONValueFree(reply);
     return ret;