From b7ef069ec75e4efc1872bbcd418d08bf8736aa2f Mon Sep 17 00:00:00 2001 From: Sukrit Bhatnagar Date: Sat, 28 Jul 2018 23:31:30 +0530 Subject: [PATCH] util: netdevmacvlan: use VIR_AUTOFREE instead of VIR_FREE for scalar types 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 --- src/util/virnetdevmacvlan.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/util/virnetdevmacvlan.c b/src/util/virnetdevmacvlan.c index fb41bf934c..32062cbc2c 100644 --- a/src/util/virnetdevmacvlan.c +++ b/src/util/virnetdevmacvlan.c @@ -308,7 +308,6 @@ virNetDevMacVLanCreate(const char *ifname, int *retry) { int rc = -1; - struct nlmsghdr *resp = NULL; struct nlmsgerr *err; struct ifinfomsg ifinfo = { .ifi_family = AF_UNSPEC }; int ifindex; @@ -316,6 +315,7 @@ virNetDevMacVLanCreate(const char *ifname, struct nl_msg *nl_msg; struct nlattr *linkinfo, *info_data; char macstr[VIR_MAC_STRING_BUFLEN]; + VIR_AUTOFREE(struct nlmsghdr *) resp = NULL; if (virNetDevGetIndex(srcdev, &ifindex) < 0) return -1; @@ -403,7 +403,6 @@ virNetDevMacVLanCreate(const char *ifname, rc = 0; cleanup: nlmsg_free(nl_msg); - VIR_FREE(resp); return rc; malformed_resp: @@ -452,8 +451,8 @@ virNetDevMacVLanTapOpen(const char *ifname, { int ret = -1; int ifindex; - char *tapname = NULL; size_t i = 0; + VIR_AUTOFREE(char *) tapname = NULL; if (virNetDevGetIndex(ifname, &ifindex) < 0) return -1; @@ -487,7 +486,6 @@ virNetDevMacVLanTapOpen(const char *ifname, while (i--) VIR_FORCE_CLOSE(tapfd[i]); } - VIR_FREE(tapname); return ret; } -- GitLab