Fix a lot of unimportant memleaks caused by a CRIT_ERR
[monky] / src / freebsd.c
index 20c4e27..e1c7701 100644 (file)
 #define        FREEBSD_DEBUG
 #endif
 
-inline void proc_find_top(struct process **cpu, struct process **mem);
+__attribute__((gnu_inline)) inline void
+proc_find_top(struct process **cpu, struct process **mem);
 
 static short cpu_setup = 0;
 
-static int getsysctl(char *name, void *ptr, size_t len)
+static int getsysctl(const char *name, void *ptr, size_t len)
 {
        size_t nlen = len;
 
@@ -109,11 +110,11 @@ static int swapmode(unsigned long *retavail, unsigned long *retfree)
        return n;
 }
 
-void prepare_update()
+void prepare_update(void)
 {
 }
 
-void update_uptime()
+void update_uptime(void)
 {
        int mib[2] = { CTL_KERN, KERN_BOOTTIME };
        struct timeval boottime;
@@ -145,7 +146,7 @@ int check_mount(char *s)
        return 0;
 }
 
-void update_meminfo()
+void update_meminfo(void)
 {
        u_int total_pages, inactive_pages, free_pages;
        unsigned long swap_avail, swap_free;
@@ -171,13 +172,15 @@ void update_meminfo()
        if ((swapmode(&swap_avail, &swap_free)) >= 0) {
                info.swapmax = swap_avail;
                info.swap = (swap_avail - swap_free);
+               info.swapfree = swap_free;
        } else {
                info.swapmax = 0;
                info.swap = 0;
+               info.swapfree = 0;
        }
 }
 
-void update_net_stats()
+void update_net_stats(void)
 {
        struct net_stat *ns;
        double delta;
@@ -196,7 +199,7 @@ void update_net_stats()
        }
 
        for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
-               ns = get_net_stat((const char *) ifa->ifa_name);
+               ns = get_net_stat((const char *) ifa->ifa_name, NULL, NULL);
 
                if (ifa->ifa_flags & IFF_UP) {
                        struct ifaddrs *iftmp;
@@ -250,7 +253,7 @@ void update_net_stats()
        freeifaddrs(ifap);
 }
 
-void update_total_processes()
+void update_total_processes(void)
 {
        int n_processes;
 
@@ -259,7 +262,7 @@ void update_total_processes()
        info.procs = n_processes;
 }
 
-void update_running_processes()
+void update_running_processes(void)
 {
        struct kinfo_proc *p;
        int n_processes;
@@ -286,7 +289,7 @@ struct cpu_load_struct {
 struct cpu_load_struct fresh = { {0, 0, 0, 0, 0} };
 long cpu_used, oldtotal, oldused;
 
-void get_cpu_count()
+void get_cpu_count(void)
 {
        /* int cpu_count = 0; */
 
@@ -308,11 +311,11 @@ void get_cpu_count()
 }
 
 /* XXX: SMP support */
-void update_cpu_usage()
+void update_cpu_usage(void)
 {
        long used, total;
        long cp_time[CPUSTATES];
-       size_t len = sizeof(cp_time);
+       size_t cp_len = sizeof(cp_time);
 
        /* add check for !info.cpu_usage since that mem is freed on a SIGUSR1 */
        if ((cpu_setup == 0) || (!info.cpu_usage)) {
@@ -320,7 +323,7 @@ void update_cpu_usage()
                cpu_setup = 1;
        }
 
-       if (sysctlbyname("kern.cp_time", &cp_time, &len, NULL, 0) < 0) {
+       if (sysctlbyname("kern.cp_time", &cp_time, &cp_len, NULL, 0) < 0) {
                fprintf(stderr, "Cannot get kern.cp_time");
        }
 
@@ -344,7 +347,7 @@ void update_cpu_usage()
        oldtotal = total;
 }
 
-void update_load_average()
+void update_load_average(void)
 {
        double v[3];
 
@@ -358,6 +361,7 @@ void update_load_average()
 double get_acpi_temperature(int fd)
 {
        int temp;
+       (void)fd;
 
        if (GETSYSCTL("hw.acpi.thermal.tz0.temperature", temp)) {
                fprintf(stderr,
@@ -386,6 +390,7 @@ static void get_battery_stats(int *battime, int *batcapacity, int *batstate, int
 void get_battery_stuff(char *buf, unsigned int n, const char *bat, int item)
 {
        int battime, batcapacity, batstate, ac;
+       (void)bat;
 
        get_battery_stats(&battime, &batcapacity, &batstate, &ac);
 
@@ -466,6 +471,7 @@ int get_battery_perct_bar(const char *bar)
 
 int open_acpi_temperature(const char *name)
 {
+       (void)name;
        /* Not applicable for FreeBSD. */
        return 0;
 }
@@ -517,7 +523,7 @@ void get_adt746x_fan(char *p_client_buffer, size_t client_buffer_size)
 /* rdtsc() and get_freq_dynamic() copied from linux.c */
 
 #if  defined(__i386) || defined(__x86_64)
-__inline__ unsigned long long int rdtsc()
+__attribute__((gnu_inline)) inline unsigned long long int rdtsc(void)
 {
        unsigned long long int x;
 
@@ -587,13 +593,13 @@ char get_freq(char *p_client_buffer, size_t client_buffer_size, const char *p_fo
        return 1;
 }
 
-void update_top()
+void update_top(void)
 {
        proc_find_top(info.cpu, info.memu);
 }
 
 #if 0
-void update_wifi_stats()
+void update_wifi_stats(void)
 {
        struct ifreq ifr;               /* interface stats */
        struct wi_req wireq;
@@ -608,7 +614,7 @@ void update_wifi_stats()
        }
 
        for (ifa = ifap; ifa; ifa = ifa->ifa_next) {
-               ns = get_net_stat((const char *) ifa->ifa_name);
+               ns = get_net_stat((const char *) ifa->ifa_name, NULL, NULL);
 
                s = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
 
@@ -647,7 +653,7 @@ cleanup:
 }
 #endif
 
-void update_diskio()
+void update_diskio(void)
 {
        int devs_count, num_selected, num_selections, dn;
        struct device_selection *dev_select = NULL;
@@ -703,9 +709,9 @@ void update_diskio()
 
 int comparecpu(const void *a, const void *b)
 {
-       if (((struct process *)a)->amount > ((struct process *)b)->amount) {
+       if (((const struct process *)a)->amount > ((const struct process *)b)->amount) {
                return -1;
-       } else if (((struct process *)a)->amount < ((struct process *)b)->amount) {
+       } else if (((const struct process *)a)->amount < ((const struct process *)b)->amount) {
                return 1;
        } else {
                return 0;
@@ -714,16 +720,17 @@ int comparecpu(const void *a, const void *b)
 
 int comparemem(const void *a, const void *b)
 {
-       if (((struct process *)a)->totalmem > ((struct process *)b)->totalmem) {
+       if (((const struct process *)a)->totalmem > ((const struct process *)b)->totalmem) {
                return -1;
-       } else if (((struct process *)a)->totalmem < ((struct process *)b)->totalmem) {
+       } else if (((const struct process *)a)->totalmem < ((const struct process *)b)->totalmem) {
                return 1;
        } else {
                return 0;
        }
 }
 
-inline void proc_find_top(struct process **cpu, struct process **mem)
+__attribute__((gnu_inline)) inline void
+proc_find_top(struct process **cpu, struct process **mem)
 {
        struct kinfo_proc *p;
        int n_processes;
@@ -820,10 +827,10 @@ int apm_getinfo(int fd, apm_info_t aip)
        return 0;
 }
 
-char *get_apm_adapter()
+char *get_apm_adapter(void)
 {
        int fd;
-       struct apm_info info;
+       struct apm_info a_info;
        char *out;
 
        out = (char *) calloc(16, sizeof(char));
@@ -834,20 +841,20 @@ char *get_apm_adapter()
                return out;
        }
 
-       if (apm_getinfo(fd, &info) != 0) {
+       if (apm_getinfo(fd, &a_info) != 0) {
                close(fd);
                strncpy(out, "ERR", 16);
                return out;
        }
        close(fd);
 
-       switch (info.ai_acline) {
+       switch (a_info.ai_acline) {
                case 0:
                        strncpy(out, "off-line", 16);
                        return out;
                        break;
                case 1:
-                       if (info.ai_batt_stat == 3) {
+                       if (a_info.ai_batt_stat == 3) {
                                strncpy(out, "charging", 16);
                                return out;
                        } else {
@@ -862,11 +869,11 @@ char *get_apm_adapter()
        }
 }
 
-char *get_apm_battery_life()
+char *get_apm_battery_life(void)
 {
        int fd;
        u_int batt_life;
-       struct apm_info info;
+       struct apm_info a_info;
        char *out;
 
        out = (char *) calloc(16, sizeof(char));
@@ -877,14 +884,14 @@ char *get_apm_battery_life()
                return out;
        }
 
-       if (apm_getinfo(fd, &info) != 0) {
+       if (apm_getinfo(fd, &a_info) != 0) {
                close(fd);
                strncpy(out, "ERR", 16);
                return out;
        }
        close(fd);
 
-       batt_life = info.ai_batt_life;
+       batt_life = a_info.ai_batt_life;
        if (batt_life == APM_UNKNOWN) {
                strncpy(out, "unknown", 16);
        } else if (batt_life <= 100) {
@@ -897,12 +904,12 @@ char *get_apm_battery_life()
        return out;
 }
 
-char *get_apm_battery_time()
+char *get_apm_battery_time(void)
 {
        int fd;
        int batt_time;
        int h, m, s;
-       struct apm_info info;
+       struct apm_info a_info;
        char *out;
 
        out = (char *) calloc(16, sizeof(char));
@@ -913,14 +920,14 @@ char *get_apm_battery_time()
                return out;
        }
 
-       if (apm_getinfo(fd, &info) != 0) {
+       if (apm_getinfo(fd, &a_info) != 0) {
                close(fd);
                strncpy(out, "ERR", 16);
                return out;
        }
        close(fd);
 
-       batt_time = info.ai_batt_time;
+       batt_time = a_info.ai_batt_time;
 
        if (batt_time == -1) {
                strncpy(out, "unknown", 16);