From 1d2ad16e5c846447eb186173decd1dc2883ad817 Mon Sep 17 00:00:00 2001 From: Anthony Dempsey Date: Mon, 7 Dec 2015 13:34:31 +0000 Subject: Stop memory leak rename function for convention Renamed netlink_populate_intf_struct to netlink_if_link_populate to fit with file naming scheme. It was possible that a created ifp structure would not be cleaned up if netlink_if_link_populate returned a -1, fixed this so the structure is FREEd. Signed-off-by: Anthony Dempsey (cherry picked from commit e5a8824007495c2e99b49713b18b9fb7fa8c2c3c) --- keepalived/include/vrrp_netlink.h | 2 +- keepalived/vrrp/vrrp_netlink.c | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/keepalived/include/vrrp_netlink.h b/keepalived/include/vrrp_netlink.h index 77787c9..f4ab91b 100644 --- a/keepalived/include/vrrp_netlink.h +++ b/keepalived/include/vrrp_netlink.h @@ -81,6 +81,6 @@ extern int netlink_interface_lookup(void); extern int netlink_interface_refresh(void); extern void kernel_netlink_init(void); extern void kernel_netlink_close(void); -extern int netlink_populate_intf_struct(interface_t *, struct rtattr*[], struct ifinfomsg *); +extern int netlink_if_link_populate(interface_t *, struct rtattr*[], struct ifinfomsg *); #endif diff --git a/keepalived/vrrp/vrrp_netlink.c b/keepalived/vrrp/vrrp_netlink.c index 67bf792..c2b2702 100644 --- a/keepalived/vrrp/vrrp_netlink.c +++ b/keepalived/vrrp/vrrp_netlink.c @@ -514,7 +514,8 @@ netlink_request(nl_handle_t *nl, int family, int type) } int -netlink_populate_intf_struct(interface_t *ifp, struct rtattr *tb[], struct ifinfomsg *ifi) { +netlink_if_link_populate(interface_t *ifp, struct rtattr *tb[], struct ifinfomsg *ifi) +{ char *name; int i; @@ -598,9 +599,11 @@ netlink_if_link_filter(struct sockaddr_nl *snl, struct nlmsghdr *h) /* Fill the interface structure */ ifp = (interface_t *) MALLOC(sizeof(interface_t)); - status = netlink_populate_intf_struct(ifp, tb, ifi); - if (status < 0) + status = netlink_if_link_populate(ifp, tb, ifi); + if (status < 0) { + FREE(ifp); return -1; + } /* Queue this new interface_t */ if_add_queue(ifp); return 0; @@ -765,7 +768,7 @@ netlink_reflect_filter(struct sockaddr_nl *snl, struct nlmsghdr *h) } else { memset(ifp, 0, sizeof(interface_t)); } - status = netlink_populate_intf_struct(ifp, tb, ifi); + status = netlink_if_link_populate(ifp, tb, ifi); if (status < 0) return -1; -- 1.7.12.1