1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-27 04:32:55 +00:00

Fix possible mem leak with net stats.

This commit is contained in:
Brenden Matthews 2009-03-16 15:56:37 -06:00
parent b18628ad98
commit 293f6ad7e2
2 changed files with 8 additions and 11 deletions

View File

@ -55,7 +55,9 @@ struct net_stat {
long long recv, trans; long long recv, trans;
double recv_speed, trans_speed; double recv_speed, trans_speed;
struct sockaddr addr; struct sockaddr addr;
char* addrs; #if defined(__linux__)
char addrs[273];
#endif /* __linux__ */
double net_rec[15], net_trans[15]; double net_rec[15], net_trans[15];
// wireless extensions // wireless extensions
char essid[32]; char essid[32];

View File

@ -381,9 +381,6 @@ void update_net_stats(void)
ns->up = 1; ns->up = 1;
memset(&(ns->addr.sa_data), 0, 14); memset(&(ns->addr.sa_data), 0, 14);
if(NULL == ns->addrs)
ns->addrs = (char*) malloc(17 * 16 + 1);
if(NULL != ns->addrs)
memset(ns->addrs, 0, 17 * 16 + 1); /* Up to 17 chars per ip, max 16 interfaces. Nasty memory usage... */ memset(ns->addrs, 0, 17 * 16 + 1); /* Up to 17 chars per ip, max 16 interfaces. Nasty memory usage... */
last_recv = ns->recv; last_recv = ns->recv;
@ -426,7 +423,6 @@ void update_net_stats(void)
ns2 = get_net_stat( ns2 = get_net_stat(
((struct ifreq *) conf.ifc_buf)[k].ifr_ifrn.ifrn_name); ((struct ifreq *) conf.ifc_buf)[k].ifr_ifrn.ifrn_name);
ns2->addr = ((struct ifreq *) conf.ifc_buf)[k].ifr_ifru.ifru_addr; ns2->addr = ((struct ifreq *) conf.ifc_buf)[k].ifr_ifru.ifru_addr;
if(NULL != ns2->addrs) {
sprintf(temp_addr, "%u.%u.%u.%u, ", sprintf(temp_addr, "%u.%u.%u.%u, ",
ns2->addr.sa_data[2] & 255, ns2->addr.sa_data[2] & 255,
ns2->addr.sa_data[3] & 255, ns2->addr.sa_data[3] & 255,
@ -435,7 +431,6 @@ void update_net_stats(void)
if(NULL == strstr(ns2->addrs, temp_addr)) if(NULL == strstr(ns2->addrs, temp_addr))
strncpy(ns2->addrs + strlen(ns2->addrs), temp_addr, 17); strncpy(ns2->addrs + strlen(ns2->addrs), temp_addr, 17);
} }
}
close((long) i); close((long) i);