[libvirt] [PATCH v1 39/40] util: lease: use VIR_AUTOFREE instead of VIR_FREE for scalar types

Sukrit Bhatnagar posted 40 patches 7 years, 6 months ago
There is a newer version of this series
[libvirt] [PATCH v1 39/40] util: lease: use VIR_AUTOFREE instead of VIR_FREE for scalar types
Posted by Sukrit Bhatnagar 7 years, 6 months ago
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 <skrtbhtngr@gmail.com>
---
 src/util/virlease.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/src/util/virlease.c b/src/util/virlease.c
index b49105d..baaceaf 100644
--- a/src/util/virlease.c
+++ b/src/util/virlease.c
@@ -55,7 +55,7 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new,
                             const char *ip_to_delete,
                             char **server_duid)
 {
-    char *lease_entries = NULL;
+    VIR_AUTOFREE(char *) lease_entries = NULL;
     virJSONValuePtr leases_array = NULL;
     long long expirytime;
     int custom_lease_file_len = 0;
@@ -146,7 +146,6 @@ virLeaseReadCustomLeaseFile(virJSONValuePtr leases_array_new,
 
  cleanup:
     virJSONValueFree(leases_array);
-    VIR_FREE(lease_entries);
     return ret;
 }
 
@@ -235,7 +234,7 @@ virLeaseNew(virJSONValuePtr *lease_ret,
     virJSONValuePtr lease_new = NULL;
     const char *exptime_tmp = virGetEnvAllowSUID("DNSMASQ_LEASE_EXPIRES");
     long long expirytime = 0;
-    char *exptime = NULL;
+    VIR_AUTOFREE(char *) exptime = NULL;
     int ret = -1;
 
     /* In case hostname is still unknown, use the last known one */
@@ -291,7 +290,6 @@ virLeaseNew(virJSONValuePtr *lease_ret,
     *lease_ret = lease_new;
     lease_new = NULL;
  cleanup:
-    VIR_FREE(exptime);
     virJSONValueFree(lease_new);
     return ret;
 }
-- 
1.8.3.1

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH v1 39/40] util: lease: use VIR_AUTOFREE instead of VIR_FREE for scalar types
Posted by Erik Skultety 7 years, 6 months ago
On Sat, Jul 21, 2018 at 05:37:11PM +0530, Sukrit Bhatnagar wrote:
> 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 <skrtbhtngr@gmail.com>
> ---
Reviewed-by: Erik Skultety <eskultet@redhat.com>

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