Re: [libvirt] [PATCH v1 19/32] util: netdevtap: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-08-03 Thread Erik Skultety
On Sat, Jul 28, 2018 at 11:31:34PM +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 
> ---
Reviewed-by: Erik Skultety 

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


[libvirt] [PATCH v1 19/32] util: netdevtap: use VIR_AUTOFREE instead of VIR_FREE for scalar types

2018-07-28 Thread Sukrit Bhatnagar
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 
---
 src/util/virnetdevtap.c | 11 +++
 1 file changed, 3 insertions(+), 8 deletions(-)

diff --git a/src/util/virnetdevtap.c b/src/util/virnetdevtap.c
index d432577..c2c2e73 100644
--- a/src/util/virnetdevtap.c
+++ b/src/util/virnetdevtap.c
@@ -400,16 +400,14 @@ int virNetDevTapCreate(char **ifname,
 if (strstr(*ifname, "%d") != NULL) {
 size_t i;
 for (i = 0; i <= IF_MAXUNIT; i++) {
-char *newname;
+VIR_AUTOFREE(char *) newname = NULL;
 if (virAsprintf(, *ifname, i) < 0)
 goto cleanup;
 
 if (virNetDevExists(newname) == 0) {
-newifname = newname;
+VIR_STEAL_PTR(newifname, newname);
 break;
 }
-
-VIR_FREE(newname);
 }
 if (newifname) {
 VIR_FREE(*ifname);
@@ -423,7 +421,7 @@ int virNetDevTapCreate(char **ifname,
 }
 
 if (tapfd) {
-char *dev_path = NULL;
+VIR_AUTOFREE(char *) dev_path = NULL;
 if (virAsprintf(_path, "/dev/%s", ifr.ifr_name) < 0)
 goto cleanup;
 
@@ -431,11 +429,8 @@ int virNetDevTapCreate(char **ifname,
 virReportSystemError(errno,
  _("Unable to open %s"),
  dev_path);
-VIR_FREE(dev_path);
 goto cleanup;
 }
-
-VIR_FREE(dev_path);
 }
 
 if (virNetDevSetName(ifr.ifr_name, *ifname) == -1)
-- 
1.8.3.1

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