1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-01-12 13:17:58 +03:00

virJSONValueNewArrayFromBitmap: Refactor cleanup

Use g_autoptr for the JSON value objects and remove the cleanup label
and inline freeing of objects.

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 10:55:56 +01:00
parent 7d3a33b26b
commit 94ab321ffc

View File

@ -1241,29 +1241,21 @@ virJSONValueGetArrayAsBitmap(const virJSONValue *val,
virJSONValuePtr
virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap)
{
virJSONValuePtr ret;
g_autoptr(virJSONValue) ret = virJSONValueNewArray();
ssize_t pos = -1;
ret = virJSONValueNewArray();
if (!bitmap)
return ret;
return g_steal_pointer(&ret);
while ((pos = virBitmapNextSetBit(bitmap, pos)) > -1) {
virJSONValuePtr newelem;
g_autoptr(virJSONValue) newelem = virJSONValueNewNumberLong(pos);
if (!(newelem = virJSONValueNewNumberLong(pos)) ||
virJSONValueArrayAppend(ret, newelem) < 0) {
virJSONValueFree(newelem);
goto error;
}
if (virJSONValueArrayAppend(ret, newelem) < 0)
return NULL;
newelem = NULL;
}
return ret;
error:
virJSONValueFree(ret);
return NULL;
return g_steal_pointer(&ret);
}