From ea4cba6ca6c5da770edcf104ee8f826ca5f86466 Mon Sep 17 00:00:00 2001 From: Wei Bai Date: Tue, 30 Apr 2019 04:16:19 +0800 Subject: [PATCH] [fpmsyncd] Fix memory leak bug (#864) * Fix netlink memory leak of fpmsyncd * Refill netlink cache instead of reallocation * Allocate netlink socket and cache on the constructor function --- fpmsyncd/routesync.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/fpmsyncd/routesync.cpp b/fpmsyncd/routesync.cpp index 414e9ed3a4e0..8f05338f2d53 100644 --- a/fpmsyncd/routesync.cpp +++ b/fpmsyncd/routesync.cpp @@ -21,7 +21,8 @@ RouteSync::RouteSync(RedisPipeline *pipeline) : m_routeTable(pipeline, APP_ROUTE_TABLE_NAME, true), m_vnet_routeTable(pipeline, APP_VNET_RT_TABLE_NAME, true), m_vnet_tunnelTable(pipeline, APP_VNET_RT_TUNNEL_TABLE_NAME, true), - m_warmStartHelper(pipeline, &m_routeTable, APP_ROUTE_TABLE_NAME, "bgp", "bgp") + m_warmStartHelper(pipeline, &m_routeTable, APP_ROUTE_TABLE_NAME, "bgp", "bgp"), + m_nl_sock(NULL), m_link_cache(NULL) { m_nl_sock = nl_socket_alloc(); nl_connect(m_nl_sock, NETLINK_ROUTE); @@ -291,7 +292,8 @@ bool RouteSync::getIfName(int if_index, char *if_name, size_t name_len) /* Cannot get interface name. Possibly the interface gets re-created. */ if (!rtnl_link_i2name(m_link_cache, if_index, if_name, name_len)) { - rtnl_link_alloc_cache(m_nl_sock, AF_UNSPEC, &m_link_cache); + /* Trying to refill cache */ + nl_cache_refill(m_nl_sock, m_link_cache); if (!rtnl_link_i2name(m_link_cache, if_index, if_name, name_len)) { return false;