]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
util: netdevmacvlan: use VIR_AUTOFREE instead of VIR_FREE for scalar types
authorSukrit Bhatnagar <skrtbhtngr@gmail.com>
Sat, 28 Jul 2018 18:01:30 +0000 (23:31 +0530)
committerErik Skultety <eskultet@redhat.com>
Tue, 7 Aug 2018 14:29:55 +0000 (16:29 +0200)
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>
src/util/virnetdevmacvlan.c

index fb41bf934cf90b769b1caf69294ab08690453d5f..32062cbc2cc67de1c0b4922b484548a2061ba998 100644 (file)
@@ -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;
 }