By making use of GNU C's cleanup attribute handled by the
VIR_AUTOFREE macro for declaring scalar variables, majority
of the VIR_FREE calls can be dropped, which in turn leads to
getting rid of most of our cleanup sections.

Signed-off-by: Sukrit Bhatnagar <skrtbht...@gmail.com>
---
 src/util/virqemu.c | 26 +++++++-------------------
 1 file changed, 7 insertions(+), 19 deletions(-)

diff --git a/src/util/virqemu.c b/src/util/virqemu.c
index 30b8dc1..4089b8e 100644
--- a/src/util/virqemu.c
+++ b/src/util/virqemu.c
@@ -85,29 +85,22 @@ virQEMUBuildCommandLineJSONArrayNumbered(const char *key,
                                          virBufferPtr buf)
 {
     virJSONValuePtr member;
-    char *prefix = NULL;
     size_t i;
-    int ret = 0;
 
     for (i = 0; i < virJSONValueArraySize(array); i++) {
+        VIR_AUTOFREE(char *) prefix = NULL;
         member = virJSONValueArrayGet((virJSONValuePtr) array, i);
 
         if (virAsprintf(&prefix, "%s.%zu", key, i) < 0)
-            goto cleanup;
+            return 0;
 
         if (virQEMUBuildCommandLineJSONRecurse(prefix, member, buf,
                                                
virQEMUBuildCommandLineJSONArrayNumbered,
                                                true) < 0)
-            goto cleanup;
-
-        VIR_FREE(prefix);
+            return 0;
     }
 
-    ret = 0;
-
- cleanup:
-    VIR_FREE(prefix);
-    return ret;
+    return 0;
 }
 
 
@@ -118,23 +111,18 @@ virQEMUBuildCommandLineJSONIterate(const char *key,
                                    void *opaque)
 {
     struct virQEMUCommandLineJSONIteratorData *data = opaque;
-    char *tmpkey = NULL;
-    int ret = -1;
 
     if (data->prefix) {
+        VIR_AUTOFREE(char *) tmpkey = NULL;
         if (virAsprintf(&tmpkey, "%s.%s", data->prefix, key) < 0)
             return -1;
 
-        ret = virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
+        return virQEMUBuildCommandLineJSONRecurse(tmpkey, value, data->buf,
                                                  data->arrayFunc, false);
-
-        VIR_FREE(tmpkey);
     } else {
-        ret = virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
+        return virQEMUBuildCommandLineJSONRecurse(key, value, data->buf,
                                                  data->arrayFunc, false);
     }
-
-    return ret;
 }
 
 
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list

Reply via email to