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 <skrtbht...@gmail.com> Reviewed-by: Erik Skultety <eskul...@redhat.com> --- src/util/virjson.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/src/util/virjson.c b/src/util/virjson.c index 82f539f..29530dc 100644 --- a/src/util/virjson.c +++ b/src/util/virjson.c @@ -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; } -- 1.8.3.1 -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list