[PATCH v3 25/35] util: json: use VIR_AUTOPTR for aggregate types

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
 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@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux