1
0
mirror of https://github.com/Llewellynvdm/conky.git synced 2024-12-26 12:27:52 +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,10 +381,7 @@ 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) memset(ns->addrs, 0, 17 * 16 + 1); /* Up to 17 chars per ip, max 16 interfaces. Nasty memory usage... */
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... */
last_recv = ns->recv; last_recv = ns->recv;
last_trans = ns->trans; last_trans = ns->trans;
@ -424,17 +421,15 @@ void update_net_stats(void)
break; break;
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,
ns2->addr.sa_data[4] & 255, ns2->addr.sa_data[4] & 255,
ns2->addr.sa_data[5] & 255); ns2->addr.sa_data[5] & 255);
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);