By making use of the GCC's __attribute__((cleanup)) handled by VIR_AUTOPTR
macro, majority of the calls to *Free functions can be dropped, which in
turn leads to getting rid of most of our cleanup sections.
---
src/util/virjson.c | 15 ++++-----------
1 file changed, 4 insertions(+), 11 deletions(-)
diff --git a/src/util/virjson.c b/src/util/virjson.c
index 1391a3b..3b54d94 100644
--- a/src/util/virjson.c
+++ b/src/util/virjson.c
@@ -2033,16 +2033,12 @@ char *
virJSONStringReformat(const char *jsonstr,
bool pretty)
{
- virJSONValuePtr json;
- char *ret;
+ VIR_AUTOPTR(virJSONValuePtr) json = NULL;
if (!(json = virJSONValueFromString(jsonstr)))
return NULL;
- ret = virJSONValueToString(json, pretty);
-
- virJSONValueFree(json);
- return ret;
+ return virJSONValueToString(json, pretty);
}
@@ -2131,7 +2127,7 @@ virJSONValueObjectDeflattenWorker(const char *key,
virJSONValuePtr
virJSONValueObjectDeflatten(virJSONValuePtr json)
{
- virJSONValuePtr deflattened;
+ VIR_AUTOPTR(virJSONValuePtr) deflattened = NULL;
virJSONValuePtr ret = NULL;
if (!(deflattened = virJSONValueNewObject()))
@@ -2140,12 +2136,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