From: Andreas Fink Date: Sun, 10 Jan 2010 22:16:27 +0000 (+0000) Subject: *fix* 2 memleaks X-Git-Url: https://git.dogcows.com/gitweb?p=chaz%2Ftint2;a=commitdiff_plain;h=d58d40cf86b22fb1339afb8ce9775182462162e5 *fix* 2 memleaks *fix* no more warnings --- diff --git a/sample/white_single_desktop.tint2rc b/sample/white_single_desktop.tint2rc index a6cd964..d5311a0 100644 --- a/sample/white_single_desktop.tint2rc +++ b/sample/white_single_desktop.tint2rc @@ -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 diff --git a/src/battery/battery.c b/src/battery/battery.c index fadf968..8d64f82 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -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; diff --git a/src/panel.c b/src/panel.c index 3250806..c5597cb 100644 --- a/src/panel.c +++ b/src/panel.c @@ -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; + } } diff --git a/src/server.c b/src/server.c index 978266f..c1401ae 100644 --- a/src/server.c +++ b/src/server.c @@ -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); } diff --git a/src/taskbar/task.c b/src/taskbar/task.c index d14f8fa..92a6ff8 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -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; knext) { traywin = (TrayWindow*)l->data; if ( traywin->id == de->drawable && !de->more ) { diff --git a/src/util/common.c b/src/util/common.c index dd2f011..8e213fc 100644 --- a/src/util/common.c +++ b/src/util/common.c @@ -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); diff --git a/src/util/timer.c b/src/util/timer.c index e722252..797ece0 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -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); }