nl_cache_refill leak suppose

SlavAg hcs at inbox.ru
Sun Jun 4 22:11:21 PDT 2017


Hello everybody,

Have some problem with nl_cache_refill (and rtnl_link_alloc_cache too).
When Im calling it periodically memory using by top enlarge.
To avoid overhead i dont close nl socket and dont disconnect it. Keep it 
ready between calls.
Before I am working with caches like this 
https://www.infradead.org/~tgr/libnl/doc/route.html and have same memory 
leaking. If I use rtnl_link_get_kernel instead - there is no problem 
with memory.

version libnl 3.2.25 arch arm.

int intf_get_stat (int intfindex,intf_stat *stat){
	uint32_t ifindex;
	struct rtnl_link *link;
     int err;

     ifindex = intfindex+2; // strict since eth0 = index 2

     if(statsock==NULL){
//    statsock = nl_cli_alloc_socket();
         if (!(statsock = nl_socket_alloc())){
         	printf( "Unable to allocate netlink socket");
         	return -1;
		} else {
//			nl_cli_connect(statsock, NETLINK_ROUTE);

	        if ((err = nl_connect(statsock, NETLINK_ROUTE)) < 0){
	                printf( "Unable to connect netlink socket: %s",
	                             nl_geterror(err));
				return -2;

	        }
		}

     }
	if(stat_link_cache==NULL){
		if ((err = rtnl_link_alloc_cache(statsock, AF_UNSPEC, 
&stat_link_cache)) < 0) {
			printf("Unable to allocate link cache: %s",nl_geterror(err));
			return -3;
		} else {

		}
	} else {
		if((err = nl_cache_refill	(	statsock, stat_link_cache)) < 0){
			printf("Unable to refill link cache: %s",nl_geterror(err));
			return -4;

		}


	}
/*
  *
     if ((err = rtnl_link_alloc_cache(statsock, AF_UNSPEC, &link_cache)) 
< 0) {
		printf("Unable to allocate link cache: %s",nl_geterror(err));
		return -1;
     } else {
*/
/*
     	if((err = rtnl_link_get_kernel(statsock, ifindex, NULL, &link)) < 0){
             printf( "Unable to get kernel link: %s",
                          nl_geterror(err));
             return -1;

     	}
*/
		link = rtnl_link_get(stat_link_cache, ifindex);
         printf("link index %d\n",ifindex);
         stat->link_rx_packets = rtnl_link_get_stat(link, 
RTNL_LINK_RX_PACKETS);
         printf("link_rx_packets %d\n",stat->link_rx_packets);
         stat->link_tx_packets = rtnl_link_get_stat(link, 
RTNL_LINK_TX_PACKETS);
         printf("link_tx_packets %d\n",stat->link_tx_packets);
         stat->link_rx_bytes = rtnl_link_get_stat(link, RTNL_LINK_RX_BYTES);
         printf("link_rx_bytes %d\n",stat->link_rx_bytes);
         stat->link_tx_bytes = rtnl_link_get_stat(link, RTNL_LINK_TX_BYTES);
         printf("link_tx_bytes %d\n",stat->link_tx_bytes);
         stat->link_rx_errors = rtnl_link_get_stat(link, 
RTNL_LINK_RX_ERRORS);
         stat->link_tx_errors = rtnl_link_get_stat(link, 
RTNL_LINK_TX_ERRORS);
         stat->link_rx_dropped = rtnl_link_get_stat(link, 
RTNL_LINK_RX_DROPPED);
         stat->link_tx_dropped = rtnl_link_get_stat(link, 
RTNL_LINK_TX_DROPPED);
         stat->link_rx_compressed = rtnl_link_get_stat(link, 
RTNL_LINK_RX_COMPRESSED);
         stat->link_tx_compressed = rtnl_link_get_stat(link, 
RTNL_LINK_TX_COMPRESSED);
         stat->link_rx_fifo_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_FIFO_ERR);
         stat->link_tx_fifo_err = rtnl_link_get_stat(link, 
RTNL_LINK_TX_FIFO_ERR);
         stat->link_rx_len_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_LEN_ERR);
         stat->link_rx_over_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_OVER_ERR);
         stat->link_rx_crc_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_CRC_ERR);
         stat->link_rx_frame_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_FRAME_ERR);
         stat->link_rx_missed_err = rtnl_link_get_stat(link, 
RTNL_LINK_RX_MISSED_ERR);
         stat->link_tx_abort_err = rtnl_link_get_stat(link, 
RTNL_LINK_TX_ABORT_ERR);
         stat->link_tx_carrier_err = rtnl_link_get_stat(link, 
RTNL_LINK_TX_CARRIER_ERR);
         stat->link_tx_hbeat_err = rtnl_link_get_stat(link, 
RTNL_LINK_TX_HBEAT_ERR); 	
         stat->link_tx_win_err = rtnl_link_get_stat(link, 
RTNL_LINK_TX_WIN_ERR);
         stat->link_collisions = rtnl_link_get_stat(link, 
RTNL_LINK_COLLISIONS);
         stat->link_multicast = rtnl_link_get_stat(link, 
RTNL_LINK_MULTICAST);

		rtnl_link_put(link);
//	printf(" c_refcnt %d\n",link_cache->c_refcnt);
/*        nl_cache_free(link_cache);

     }
*/
//	nl_socket_free(sock);
	return 0;
}

With regards,
Agafonov.




More information about the libnl mailing list