mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-03-07 17:28:15 +00: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:
parent
7d3a33b26b
commit
94ab321ffc
@ -1241,29 +1241,21 @@ virJSONValueGetArrayAsBitmap(const virJSONValue *val,
|
|||||||
virJSONValuePtr
|
virJSONValuePtr
|
||||||
virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap)
|
virJSONValueNewArrayFromBitmap(virBitmapPtr bitmap)
|
||||||
{
|
{
|
||||||
virJSONValuePtr ret;
|
g_autoptr(virJSONValue) ret = virJSONValueNewArray();
|
||||||
ssize_t pos = -1;
|
ssize_t pos = -1;
|
||||||
|
|
||||||
ret = virJSONValueNewArray();
|
|
||||||
|
|
||||||
if (!bitmap)
|
if (!bitmap)
|
||||||
return ret;
|
return g_steal_pointer(&ret);
|
||||||
|
|
||||||
while ((pos = virBitmapNextSetBit(bitmap, pos)) > -1) {
|
while ((pos = virBitmapNextSetBit(bitmap, pos)) > -1) {
|
||||||
virJSONValuePtr newelem;
|
g_autoptr(virJSONValue) newelem = virJSONValueNewNumberLong(pos);
|
||||||
|
|
||||||
if (!(newelem = virJSONValueNewNumberLong(pos)) ||
|
if (virJSONValueArrayAppend(ret, newelem) < 0)
|
||||||
virJSONValueArrayAppend(ret, newelem) < 0) {
|
|
||||||
virJSONValueFree(newelem);
|
|
||||||
goto error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ret;
|
|
||||||
|
|
||||||
error:
|
|
||||||
virJSONValueFree(ret);
|
|
||||||
return NULL;
|
return NULL;
|
||||||
|
newelem = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
return g_steal_pointer(&ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user