]> Dogcows Code - chaz/tint2/blobdiff - src/battery/battery.c
fixed some segfault and memleak
[chaz/tint2] / src / battery / battery.c
index 4dcb99a47cffab9755daa5ea7b29599fb69f717d..7e47bd32699a8f2ee9a740b3ae099372d2f2f723 100644 (file)
@@ -47,7 +47,7 @@ char *path_energy_now, *path_energy_full, *path_current_now, *path_status;
 void init_battery()
 {
        // check battery
-       GDir *directory;
+       GDir *directory = 0;
        GError *error = NULL;
        const char *entryname;
        char *battery_dir = 0;
@@ -69,7 +69,9 @@ void init_battery()
                        g_free(path1);
                }
        }
-       if (battery_dir != 0) {
+       if (directory)
+               g_dir_close(directory);
+       if (battery_dir) {
                char *path1 = g_build_filename(battery_dir, "energy_now", NULL);
                if (g_file_test (path1, G_FILE_TEST_EXISTS)) {
                        path_energy_now = g_build_filename(battery_dir, "energy_now", NULL);
@@ -94,9 +96,9 @@ void init_battery()
        }
 
        FILE *fp;
-   Panel *panel;
-   Battery *battery;
-   int i, bat_percentage_height, bat_percentage_height_ink, bat_time_height, bat_time_height_ink;
+       Panel *panel;
+       Battery *battery;
+       int i, bat_percentage_height, bat_percentage_height_ink, bat_time_height, bat_time_height_ink;
 
        for (i=0 ; i < nb_panel ; i++) {
                panel = &panel1[i];
@@ -161,6 +163,9 @@ void init_battery()
                battery->bat1_posy -= ((bat_time_height_ink + 2) / 2);
                battery->bat2_posy = battery->bat1_posy + bat_percentage_height + 2 - (bat_percentage_height - bat_percentage_height_ink)/2 - (bat_time_height - bat_time_height_ink)/2;
        }
+
+       if (battery_dir)
+               g_free(battery_dir);
 }
 
 
@@ -268,7 +273,7 @@ void draw_battery (void *obj, cairo_t *c, int active)
 
 void resize_battery(void *obj)
 {
-       Battery *battery = obj;
+       Battery *battery = obj;
        PangoLayout *layout;
        int percentage_width, time_width, new_width;
 
This page took 0.023219 seconds and 4 git commands to generate.