qemuMonitorJSONQueryRxFilterParse: Set *filter only on success

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>
This commit is contained in:
Michal Privoznik 2021-10-22 07:17:03 +02:00
parent 4e8bb57859
commit 4b1b14170a

View 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;