Skip to content

Commit

Permalink
[fpmsyncd] Fix memory leak bug (sonic-net#864)
Browse files Browse the repository at this point in the history
* Fix netlink memory leak of fpmsyncd

* Refill netlink cache instead of reallocation

* Allocate netlink socket and cache on the constructor function
  • Loading branch information
baiwei0427 authored and prsunny committed Apr 29, 2019
1 parent 713dee2 commit ea4cba6
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fpmsyncd/routesync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ea4cba6

Please sign in to comment.