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(a)redhat.com>
---
src/qemu/qemu_monitor_json.c | 12 ++----------
1 file changed, 2 insertions(+), 10 deletions(-)
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index bcbb4e59ab..26cbb8cedc 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -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;
--
2.32.0