two conky fixes
authorPhil <n0-1@users.sourceforge.net>
Mon, 24 Mar 2008 20:35:20 +0000 (20:35 +0000)
committerPhil <n0-1@users.sourceforge.net>
Mon, 24 Mar 2008 20:35:20 +0000 (20:35 +0000)
* opened file for laptop_mode wasn't closed again
* hopefully fix reading interface addresses

git-svn-id: https://conky.svn.sourceforge.net/svnroot/conky/trunk/conky1@1047 7f574dfc-610e-0410-a909-a81674777703

src/linux.c

index d1bd1ba..c4a00c8 100644 (file)
@@ -178,6 +178,7 @@ int get_laptop_mode()
 
        if ((fp = fopen("/proc/sys/vm/laptop_mode", "r")) != NULL)
                fscanf(fp, "%d\n", &val);
+       fclose(fp);
        return val;
 }
 
@@ -383,14 +384,17 @@ inline void update_net_stats()
                i = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
 
                conf.ifc_buf = malloc(sizeof(struct ifreq) * 16);
-
                conf.ifc_len = sizeof(struct ifreq) * 16;
+               memset(conf.ifc_buf, 0, conf.ifc_len);
 
                ioctl((long) i, SIOCGIFCONF, &conf);
 
                for (k = 0; k < conf.ifc_len / sizeof(struct ifreq); k++) {
                        struct net_stat *ns;
 
+                       if (!(((struct ifreq *) conf.ifc_buf) + k))
+                               break;
+
                        ns = get_net_stat(
                                ((struct ifreq *) conf.ifc_buf)[k].ifr_ifrn.ifrn_name);
                        ns->addr = ((struct ifreq *) conf.ifc_buf)[k].ifr_ifru.ifru_addr;