virMACMapHashDumper: Refactor array addition

Use automatic memory freeing and don't check return value of
virJSONValueNewString as it can't fail.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
This commit is contained in:
Peter Krempa 2021-02-12 11:34:22 +01:00
parent 83a50fe2a5
commit d4e369a4c3

View File

@ -214,13 +214,11 @@ virMACMapHashDumper(void *payload,
GSList *next;
for (next = macs; next; next = next->next) {
virJSONValuePtr m = virJSONValueNewString((const char *) next->data);
g_autoptr(virJSONValue) m = virJSONValueNewString((const char *) next->data);
if (!m ||
virJSONValueArrayAppend(arr, m) < 0) {
virJSONValueFree(m);
if (virJSONValueArrayAppend(arr, m) < 0)
return -1;
}
m = NULL;
}
if (virJSONValueObjectAppendString(obj, "domain", name) < 0 ||