]> Dogcows Code - chaz/tint2/commitdiff
*fix* 2 memleaks
authorAndreas Fink <andreas.fink85@googlemail.com>
Sun, 10 Jan 2010 22:16:27 +0000 (22:16 +0000)
committerAndreas Fink <andreas.fink85@googlemail.com>
Sun, 10 Jan 2010 22:16:27 +0000 (22:16 +0000)
*fix* no more warnings

sample/white_single_desktop.tint2rc
src/battery/battery.c
src/panel.c
src/server.c
src/taskbar/task.c
src/tint.c
src/util/common.c
src/util/timer.c

index a6cd9641f3e10edaf4360cb7d7cfe4d27a8bb337..d5311a00dc647ac494565d321ad45419a9c8d162 100644 (file)
@@ -87,6 +87,7 @@ time1_font = AvantGardeLTMedium 9 bold
 clock_font_color = #151515 60
 clock_padding = 4 0
 clock_tooltip = %A %d %B
+clock_background_id = 1
 #time1_timezone = :US/Hawaii
 #time2_timezone = :Europe/Berlin
 #clock_tooltip_timezone = :/usr/share/zoneinfo/Europe/Paris
index fadf968caa7cc2ce2c5dbb95906a38864d9a84e9..8d64f825cbf8b36243faa6af85c0013bbeda774a 100644 (file)
@@ -212,36 +212,30 @@ void update_battery() {
 
        fp = fopen(path_status, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
+               if (fgets(tmp, sizeof tmp, fp)) {
+                       battery_state.state = BATTERY_UNKNOWN;
+                       if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING;
+                       if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING;
+                       if(strcasecmp(tmp, "Full\n")==0) battery_state.state = BATTERY_FULL;
+               }
                fclose(fp);
        }
-       battery_state.state = BATTERY_UNKNOWN;
-       if(strcasecmp(tmp, "Charging\n")==0) battery_state.state = BATTERY_CHARGING;
-       if(strcasecmp(tmp, "Discharging\n")==0) battery_state.state = BATTERY_DISCHARGING;
-       if(strcasecmp(tmp, "Full\n")==0) battery_state.state = BATTERY_FULL;
-       if (battery_state.state == BATTERY_DISCHARGING) {
-       }
-       else {
-       }
 
        fp = fopen(path_energy_now, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               energy_now = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) energy_now = atoi(tmp);
                fclose(fp);
        }
 
        fp = fopen(path_energy_full, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               energy_full = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) energy_full = atoi(tmp);
                fclose(fp);
        }
 
        fp = fopen(path_current_now, "r");
        if(fp != NULL) {
-               fgets(tmp, sizeof tmp, fp);
-               current_now = atoi(tmp);
+               if (fgets(tmp, sizeof tmp, fp)) current_now = atoi(tmp);
                fclose(fp);
        }
 
@@ -268,15 +262,14 @@ void update_battery() {
        if(energy_full > 0)
                new_percentage = (energy_now*100)/energy_full;
 
-  if(battery_low_status > new_percentage && battery_state.state == BATTERY_DISCHARGING && !battery_low_cmd_send) {
-    printf("battery low, executing: %s\n", battery_low_cmd);
-    if (battery_low_cmd)
-      system(battery_low_cmd);
-    battery_low_cmd_send = 1;
+       if(battery_low_status > new_percentage && battery_state.state == BATTERY_DISCHARGING && !battery_low_cmd_send) {
+               if (battery_low_cmd)
+                       if (-1 != system(battery_low_cmd))
+                               battery_low_cmd_send = 1;
+       }
+       if(battery_low_status < new_percentage && battery_state.state == BATTERY_CHARGING && battery_low_cmd_send) {
+               battery_low_cmd_send = 0;
        }
-  if(battery_low_status < new_percentage && battery_state.state == BATTERY_CHARGING && battery_low_cmd_send) {
-    battery_low_cmd_send = 0;
-  }
 
        battery_state.percentage = new_percentage;
 
index 3250806806398a38f1b9f2ae485f15b7a6ec6c01..c5597cb36e8d0d9b4ef0ddcc8bef5fdb1e538bdb 100644 (file)
@@ -318,6 +318,11 @@ void cleanup_panel()
                pango_font_description_free(panel_config.g_task.font_desc);
                panel_config.g_task.font_desc = 0;
        }
+
+       if (backgrounds) {
+               g_array_free(backgrounds, 1);
+               backgrounds = 0;
+       }
 }
 
 
index 978266fb8497696862d497c3c19e74845d2c830d..c1401aedcc603e56cb08f6448a5ac42c7d0b621a 100644 (file)
@@ -85,6 +85,7 @@ void server_init_atoms ()
        server.atom._NET_SYSTEM_TRAY_ORIENTATION = XInternAtom(server.dsp, "_NET_SYSTEM_TRAY_ORIENTATION", False);
        server.atom._XEMBED = XInternAtom(server.dsp, "_XEMBED", False);
        server.atom._XEMBED_INFO = XInternAtom(server.dsp, "_XEMBED_INFO", False);
+       g_free(name_trayer);
 
        // drag 'n' drop
        server.atom.XdndAware = XInternAtom(server.dsp, "XdndAware", False);
@@ -95,9 +96,9 @@ void server_init_atoms ()
 
 void cleanup_server()
 {
-       XFreeColormap(server.dsp, server.colormap);
-       free(server.monitor);
-       XFreeGC(server.dsp, server.gc);
+       if (server.colormap) XFreeColormap(server.dsp, server.colormap);
+       if (server.monitor) free(server.monitor);
+       if (server.gc) XFreeGC(server.dsp, server.gc);
 }
 
 
index d14f8fa437942176b38d75f9a0c13332a42e94eb..92a6ff80a365a0ed3b47f745fc692b94e9075c4a 100644 (file)
@@ -67,8 +67,10 @@ Task *add_task (Window win)
        // even with task_on_all_desktop and with task_on_all_panel
        new_tsk.title = 0;
        int k;
-       for (k=0; k<TASK_STATE_COUNT; ++k)
+       for (k=0; k<TASK_STATE_COUNT; ++k) {
                new_tsk.icon[k] = 0;
+               new_tsk.state_pix[k] = 0;
+       }
        get_title(&new_tsk);
        get_icon(&new_tsk);
 
index 005be632814999af7ca5f25995643211bc5527a5..609a8d7cea645406314785276a21e4367098fbee 100644 (file)
@@ -157,7 +157,7 @@ void cleanup()
        if (snapshot_path) g_free(snapshot_path);
 
        cleanup_server();
-       XCloseDisplay(server.dsp);
+       if (server.dsp) XCloseDisplay(server.dsp);
 }
 
 
@@ -801,9 +801,11 @@ int main (int argc, char *argv[])
 
                                        default:
                                                if (e.type == XDamageNotify+damage_event) {
+                                                       // union needed to avoid strict-aliasing warnings by gcc
+                                                       union { XEvent e; XDamageNotifyEvent de; } event_union = {.e=e};
                                                        TrayWindow *traywin;
                                                        GSList *l;
-                                                       XDamageNotifyEvent* de = (XDamageNotifyEvent*)&e;
+                                                       XDamageNotifyEvent* de = &event_union.de;
                                                        for (l = systray.list_icons; l ; l = l->next) {
                                                                traywin = (TrayWindow*)l->data;
                                                                if ( traywin->id == de->drawable && !de->more ) {
index dd2f0113b94fceefd137b039f66c1176c6bc0a1b..8e213fcf8b72c5308ca93dcfc99ea9b1e6fe7cd9 100644 (file)
@@ -44,7 +44,9 @@ void copy_file(const char *pathSrc, const char *pathDest)
        fileDest = fopen(pathDest, "wb");
        if (fileDest == NULL) return;
 
-       while ((nb = fread(line, 1, 100, fileSrc)) > 0) fwrite(line, 1, nb, fileDest);
+       while ((nb = fread(line, 1, 100, fileSrc)) > 0)
+               if ( nb != fwrite(line, 1, nb, fileDest))
+                       printf("Error while copying file %s to %s\n", pathSrc, pathDest);
 
        fclose (fileDest);
        fclose (fileSrc);
index e7222524fcce8703abc55285308f9113f1c09750..797ece02c73e3015300dc1e702b020b705a3fe24 100644 (file)
@@ -300,7 +300,9 @@ void create_multi_timeout(timeout* t1, timeout* t2)
 
        t1->multi_timeout = mt1;
        t2->multi_timeout = mt2;
-       real_timeout->multi_timeout = real_timeout;
+       // set real_timeout->multi_timeout to something, such that we see in add_timeout_intern that
+       // it is already a multi_timeout (we never use it, except of checking for 0 ptr)
+       real_timeout->multi_timeout = (void*)real_timeout;
 
        timeout_list = g_slist_remove(timeout_list, t1);
        timeout_list = g_slist_remove(timeout_list, t2);
@@ -411,10 +413,11 @@ void stop_multi_timeout(timeout* t)
        multi_timeout_handler* mth = g_hash_table_lookup(multi_timeouts, t);
        g_hash_table_remove(multi_timeouts, mth->parent_timeout);
        while (mth->timeout_list) {
-               timeout* t = mth->timeout_list->data;
-               mth->timeout_list = g_slist_remove(mth->timeout_list, t);
-               g_hash_table_remove(multi_timeouts, t);
-               free(t);
+               timeout* t1 = mth->timeout_list->data;
+               mth->timeout_list = g_slist_remove(mth->timeout_list, t1);
+               g_hash_table_remove(multi_timeouts, t1);
+               free(t1->multi_timeout);
+               free(t1);
        }
        free(mth);
 }
This page took 0.027749 seconds and 4 git commands to generate.