mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2025-01-09 01:18:00 +03:00
util: json: use VIR_AUTOPTR for aggregate types
By making use of GNU C's cleanup attribute handled by the VIR_AUTOPTR macro for declaring aggregate pointer variables, majority of the calls to *Free functions can be dropped, which in turn leads to getting rid of most of our cleanup sections. Signed-off-by: Sukrit Bhatnagar <skrtbhtngr@gmail.com> Reviewed-by: Erik Skultety <eskultet@redhat.com>
This commit is contained in:
parent
b07ee8074e
commit
c450b55a65
@ -1786,7 +1786,7 @@ virJSONValueFromString(const char *jsonstring)
|
||||
size_t len = strlen(jsonstring);
|
||||
# ifndef WITH_YAJL2
|
||||
yajl_parser_config cfg = { 0, 1 }; /* Match yajl 2 default behavior */
|
||||
virJSONValuePtr tmp;
|
||||
VIR_AUTOPTR(virJSONValue) tmp = NULL;
|
||||
# endif
|
||||
|
||||
VIR_DEBUG("string=%s", jsonstring);
|
||||
@ -1850,7 +1850,6 @@ virJSONValueFromString(const char *jsonstring)
|
||||
jsonstring);
|
||||
else
|
||||
ret = virJSONValueArraySteal(tmp, 0);
|
||||
virJSONValueFree(tmp);
|
||||
# endif
|
||||
}
|
||||
|
||||
@ -2023,16 +2022,12 @@ char *
|
||||
virJSONStringReformat(const char *jsonstr,
|
||||
bool pretty)
|
||||
{
|
||||
virJSONValuePtr json;
|
||||
char *ret;
|
||||
VIR_AUTOPTR(virJSONValue) json = NULL;
|
||||
|
||||
if (!(json = virJSONValueFromString(jsonstr)))
|
||||
return NULL;
|
||||
|
||||
ret = virJSONValueToString(json, pretty);
|
||||
|
||||
virJSONValueFree(json);
|
||||
return ret;
|
||||
return virJSONValueToString(json, pretty);
|
||||
}
|
||||
|
||||
|
||||
@ -2121,7 +2116,7 @@ virJSONValueObjectDeflattenWorker(const char *key,
|
||||
virJSONValuePtr
|
||||
virJSONValueObjectDeflatten(virJSONValuePtr json)
|
||||
{
|
||||
virJSONValuePtr deflattened;
|
||||
VIR_AUTOPTR(virJSONValue) deflattened = NULL;
|
||||
virJSONValuePtr ret = NULL;
|
||||
|
||||
if (!(deflattened = virJSONValueNewObject()))
|
||||
@ -2130,12 +2125,9 @@ virJSONValueObjectDeflatten(virJSONValuePtr json)
|
||||
if (virJSONValueObjectForeachKeyValue(json,
|
||||
virJSONValueObjectDeflattenWorker,
|
||||
deflattened) < 0)
|
||||
goto cleanup;
|
||||
return NULL;
|
||||
|
||||
VIR_STEAL_PTR(ret, deflattened);
|
||||
|
||||
cleanup:
|
||||
virJSONValueFree(deflattened);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user