From af003d0e198de4bbcf9f066287dfbf26c179a4da Mon Sep 17 00:00:00 2001 From: o9000 Date: Sat, 11 Apr 2015 09:51:10 +0000 Subject: [PATCH] Memory management review: match char-malloc/strdup-free, gchar-g_str*/g_free; set pointers to null after free; initialize fonts/backgrounds correctly when missing from config git-svn-id: http://tint2.googlecode.com/svn/trunk@748 121b4492-b84c-0410-8b4c-0d4edfb3f3cc --- src/battery/battery.c | 51 ++++++++++++++----------- src/clock/clock.c | 65 ++++++++++++++++++++------------ src/config.c | 65 ++++++++++++++++++-------------- src/launcher/icon-theme-common.c | 4 +- src/launcher/launcher.c | 12 ++++-- src/panel.c | 34 +++++++++++------ src/panel.h | 2 + src/server.c | 24 ++++++++---- src/server.h | 2 +- src/systray/systraybar.c | 6 +-- src/taskbar/task.c | 6 +-- src/taskbar/taskbar.c | 37 ++++++++++-------- src/taskbar/taskbar.h | 4 +- src/taskbar/taskbarname.c | 26 +++++++++---- src/tint.c | 5 ++- src/tooltip/tooltip.c | 24 ++++++------ src/util/area.c | 3 ++ src/util/timer.c | 6 +-- 18 files changed, 228 insertions(+), 148 deletions(-) diff --git a/src/battery/battery.c b/src/battery/battery.c index 0652505..bcac447 100644 --- a/src/battery/battery.c +++ b/src/battery/battery.c @@ -56,10 +56,10 @@ static char buf_bat_time[20]; int8_t battery_low_status; unsigned char battery_low_cmd_sent; char *battery_low_cmd; -char *path_energy_now; -char *path_energy_full; -char *path_current_now; -char *path_status; +gchar *path_energy_now; +gchar *path_energy_full; +gchar *path_current_now; +gchar *path_status; int battery_found; #if defined(__OpenBSD__) || defined(__NetBSD__) @@ -126,17 +126,19 @@ void default_battery() battery_found = 0; percentage_hide = 101; battery_low_cmd_sent = 0; - battery_timeout = 0; - bat1_font_desc = 0; - bat2_font_desc = 0; - battery_low_cmd = 0; - path_energy_now = 0; - path_energy_full = 0; - path_current_now = 0; - path_status = 0; + battery_timeout = NULL; + bat1_font_desc = NULL; + bat2_font_desc = NULL; + battery_low_cmd = NULL; + path_energy_now = NULL; + path_energy_full = NULL; + path_current_now = NULL; + path_status = NULL; battery_state.percentage = 0; battery_state.time.hours = 0; battery_state.time.minutes = 0; + battery_state.time.seconds = 0; + battery_state.state = BATTERY_UNKNOWN; #if defined(__OpenBSD__) || defined(__NetBSD__) apm_fd = -1; #endif @@ -145,21 +147,21 @@ void default_battery() void cleanup_battery() { pango_font_description_free(bat1_font_desc); - bat1_font_desc = 0; + bat1_font_desc = NULL; pango_font_description_free(bat2_font_desc); - bat2_font_desc = 0; + bat2_font_desc = NULL; g_free(path_energy_now); - path_energy_now = 0; + path_energy_now = NULL; g_free(path_energy_full); - path_energy_full = 0; + path_energy_full = NULL; g_free(path_current_now); - path_current_now = 0; + path_current_now = NULL; g_free(path_status); - path_status = 0; - g_free(battery_low_cmd); - battery_low_cmd = 0; + path_status = NULL; + free(battery_low_cmd); + battery_low_cmd = NULL; stop_timeout(battery_timeout); - battery_timeout = 0; + battery_timeout = NULL; battery_found = 0; #if defined(__OpenBSD__) || defined(__NetBSD__) @@ -191,7 +193,7 @@ void init_battery() GDir *directory = 0; GError *error = NULL; const char *entryname; - char *battery_dir = 0; + gchar *battery_dir = 0; directory = g_dir_open("/sys/class/power_supply", 0, &error); if (error) { @@ -286,6 +288,11 @@ void init_battery_panel(void *p) if (!battery_enabled) return; + if (!bat1_font_desc) + bat1_font_desc = pango_font_description_from_string(DEFAULT_FONT); + if (!bat2_font_desc) + bat2_font_desc = pango_font_description_from_string(DEFAULT_FONT); + if (battery->area.bg == 0) battery->area.bg = &g_array_index(backgrounds, Background, 0); diff --git a/src/clock/clock.c b/src/clock/clock.c index e074c37..6938414 100644 --- a/src/clock/clock.c +++ b/src/clock/clock.c @@ -53,32 +53,43 @@ static timeout* clock_timeout; void default_clock() { clock_enabled = 0; - clock_timeout = 0; - time1_format = 0; - time1_timezone = 0; - time2_format = 0; - time2_timezone = 0; - time_tooltip_format = 0; - time_tooltip_timezone = 0; - clock_lclick_command = 0; - clock_rclick_command = 0; - time1_font_desc = 0; - time2_font_desc = 0; + clock_timeout = NULL; + time1_format = NULL; + time1_timezone = NULL; + time2_format = NULL; + time2_timezone = NULL; + time_tooltip_format = NULL; + time_tooltip_timezone = NULL; + clock_lclick_command = NULL; + clock_rclick_command = NULL; + time1_font_desc = NULL; + time2_font_desc = NULL; } void cleanup_clock() { - if (time1_font_desc) pango_font_description_free(time1_font_desc); - if (time2_font_desc) pango_font_description_free(time2_font_desc); - if (time1_format) g_free(time1_format); - if (time2_format) g_free(time2_format); - if (time_tooltip_format) g_free(time_tooltip_format); - if (time1_timezone) g_free(time1_timezone); - if (time2_timezone) g_free(time2_timezone); - if (time_tooltip_timezone) g_free(time_tooltip_timezone); - if (clock_lclick_command) g_free(clock_lclick_command); - if (clock_rclick_command) g_free(clock_rclick_command); - if (clock_timeout) stop_timeout(clock_timeout); + pango_font_description_free(time1_font_desc); + time1_font_desc = NULL; + pango_font_description_free(time2_font_desc); + time2_font_desc = NULL; + free(time1_format); + time1_format = NULL; + free(time2_format); + time2_format = NULL; + free(time_tooltip_format); + time_tooltip_format = NULL; + free(time1_timezone); + time1_timezone = NULL; + free(time2_timezone); + time2_timezone = NULL; + free(time_tooltip_timezone); + time_tooltip_timezone = NULL; + free(clock_lclick_command); + clock_lclick_command = NULL; + free(clock_rclick_command); + clock_rclick_command = NULL; + stop_timeout(clock_timeout); + clock_timeout = NULL; } @@ -138,7 +149,7 @@ int time_format_needs_sec_ticks(char *time_format) void init_clock() { - if (clock_timeout == 0) { + if (!clock_timeout) { if (time_format_needs_sec_ticks(time1_format) || time_format_needs_sec_ticks(time2_format)) { clock_timeout = add_timeout(10, 1000, update_clocks_sec, 0); @@ -154,7 +165,11 @@ void init_clock_panel(void *p) Panel *panel =(Panel*)p; Clock *clock = &panel->clock; - if (clock->area.bg == 0) + if (!time1_font_desc) + time1_font_desc = pango_font_description_from_string(DEFAULT_FONT); + if (!time2_font_desc) + time2_font_desc = pango_font_description_from_string(DEFAULT_FONT); + if (!clock->area.bg) clock->area.bg = &g_array_index(backgrounds, Background, 0); clock->area.parent = p; clock->area.panel = p; @@ -162,7 +177,7 @@ void init_clock_panel(void *p) clock->area.size_mode = SIZE_BY_CONTENT; clock->area._resize = resize_clock; // check consistency - if (time1_format == 0) + if (!time1_format) return; clock->area.resize = 1; diff --git a/src/config.c b/src/config.c index eb07574..35b9522 100644 --- a/src/config.c +++ b/src/config.c @@ -72,15 +72,17 @@ static int new_config_file; void default_config() { - config_path = 0; - snapshot_path = 0; + config_path = NULL; + snapshot_path = NULL; new_config_file = 0; } void cleanup_config() { - if (config_path) g_free(config_path); - if (snapshot_path) g_free(snapshot_path); + free(config_path); + config_path = NULL; + free(snapshot_path); + snapshot_path = NULL; } @@ -158,7 +160,7 @@ void load_launcher_app_dir(const char *path) gchar *file = g_build_filename(path, name, NULL); if (!g_file_test(file, G_FILE_TEST_IS_DIR) && g_str_has_suffix(file, ".desktop")) { - panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, (char *)strdup(file)); + panel_config.launcher.list_apps = g_slist_append(panel_config.launcher.list_apps, strdup(file)); } else if (g_file_test(file, G_FILE_TEST_IS_DIR)) { load_launcher_app_dir(file); } @@ -373,12 +375,13 @@ void add_entry (char *key, char *value) if (new_config_file == 0) { clock_enabled = 1; if (panel_items_order) { - char* tmp = g_strconcat(panel_items_order, "C", NULL); - g_free( panel_items_order ); - panel_items_order = tmp; + gchar* tmp = g_strconcat(panel_items_order, "C", NULL); + free(panel_items_order); + panel_items_order = strdup(tmp); + g_free(tmp); } else - panel_items_order = g_strdup("C"); + panel_items_order = strdup("C"); } if (strlen(value) > 0) { time1_format = strdup (value); @@ -581,12 +584,13 @@ void add_entry (char *key, char *value) if (new_config_file == 0 && systray_enabled == 0) { systray_enabled = 1; if (panel_items_order) { - char* tmp = g_strconcat(panel_items_order, "S", NULL); - g_free( panel_items_order ); - panel_items_order = tmp; + gchar* tmp = g_strconcat(panel_items_order, "S", NULL); + free(panel_items_order); + panel_items_order = strdup(tmp); + g_free(tmp); } else - panel_items_order = g_strdup("S"); + panel_items_order = strdup("S"); } extract_values(value, &value1, &value2, &value3); systray.area.paddingxlr = systray.area.paddingx = atoi (value1); @@ -734,12 +738,13 @@ void add_entry (char *key, char *value) systray_enabled = atoi(value); if (systray_enabled) { if (panel_items_order) { - char* tmp = g_strconcat(panel_items_order, "S", NULL); - g_free( panel_items_order ); - panel_items_order = tmp; + gchar* tmp = g_strconcat(panel_items_order, "S", NULL); + free(panel_items_order); + panel_items_order = strdup(tmp); + g_free(tmp); } else - panel_items_order = g_strdup("S"); + panel_items_order = strdup("S"); } } } @@ -749,12 +754,13 @@ void add_entry (char *key, char *value) battery_enabled = atoi(value); if (battery_enabled) { if (panel_items_order) { - char* tmp = g_strconcat(panel_items_order, "B", NULL); - g_free( panel_items_order ); - panel_items_order = tmp; + gchar* tmp = g_strconcat(panel_items_order, "B", NULL); + free(panel_items_order); + panel_items_order = strdup(tmp); + g_free(tmp); } else - panel_items_order = g_strdup("B"); + panel_items_order = strdup("B"); } } } @@ -771,7 +777,7 @@ void add_entry (char *key, char *value) int config_read () { const gchar * const * system_dirs; - char *path1; + gchar *path1; gint i; // follow XDG specification @@ -786,19 +792,19 @@ int config_read () g_free(path1); // copy tint2rc from system directory to user directory - char *path2 = 0; + gchar *path2 = 0; system_dirs = g_get_system_config_dirs(); for (i = 0; system_dirs[i]; i++) { path2 = g_build_filename(system_dirs[i], "tint2", "tint2rc", NULL); if (g_file_test(path2, G_FILE_TEST_EXISTS)) break; - g_free (path2); + g_free(path2); path2 = 0; } if (path2) { // copy file in user directory (path1) - char *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL); + gchar *dir = g_build_filename (g_get_user_config_dir(), "tint2", NULL); if (!g_file_test (dir, G_FILE_TEST_IS_DIR)) g_mkdir(dir, 0777); g_free(dir); @@ -836,12 +842,13 @@ int config_read_file (const char *path) if (new_config_file == 0) { taskbar_enabled = 1; if (panel_items_order) { - char* tmp = g_strconcat( "T", panel_items_order, NULL ); - g_free(panel_items_order); - panel_items_order = tmp; + gchar* tmp = g_strconcat("T", panel_items_order, NULL); + free(panel_items_order); + panel_items_order = strdup(tmp); + g_free(tmp); } else - panel_items_order = g_strdup("T"); + panel_items_order = strdup("T"); } return 1; diff --git a/src/launcher/icon-theme-common.c b/src/launcher/icon-theme-common.c index 44790a5..f44eaee 100644 --- a/src/launcher/icon-theme-common.c +++ b/src/launcher/icon-theme-common.c @@ -228,7 +228,7 @@ void load_theme_from_fs_dir(IconTheme *theme, char *dir_name) IconTheme *load_theme_from_fs(char *name, IconTheme *theme) { - char *dir_name = NULL; + gchar *dir_name = NULL; const GSList *location; for (location = get_icon_locations(); location; location = g_slist_next(location)) { gchar *path = (gchar*) location->data; @@ -255,7 +255,7 @@ IconTheme *load_theme(char *name) if (name == NULL) return NULL; - char *file_name = NULL; + gchar *file_name = NULL; const GSList *location; for (location = get_icon_locations(); location; location = g_slist_next(location)) { gchar *path = (gchar*) location->data; diff --git a/src/launcher/launcher.c b/src/launcher/launcher.c index e4703b4..796aa07 100644 --- a/src/launcher/launcher.c +++ b/src/launcher/launcher.c @@ -96,7 +96,7 @@ void init_launcher_panel(void *p) launcher->area._resize = resize_launcher; launcher->area.resize = 1; launcher->area.redraw = 1; - if (launcher->area.bg == 0) + if (!launcher->area.bg) launcher->area.bg = &g_array_index(backgrounds, Background, 0); // check consistency @@ -118,20 +118,26 @@ void cleanup_launcher() if (xsettings_client) xsettings_client_destroy(xsettings_client); - for (i = 0 ; i < nb_panel ; i++) { + xsettings_client = NULL; + + for (i = 0; i < nb_panel; i++) { Panel *panel = &panel1[i]; Launcher *launcher = &panel->launcher; cleanup_launcher_theme(launcher); } + for (l = panel_config.launcher.list_apps; l ; l = l->next) { free(l->data); } g_slist_free(panel_config.launcher.list_apps); panel_config.launcher.list_apps = NULL; + free(icon_theme_name_config); icon_theme_name_config = NULL; + free(icon_theme_name_xsettings); icon_theme_name_xsettings = NULL; + launcher_enabled = 0; } @@ -153,9 +159,9 @@ void cleanup_launcher_theme(Launcher *launcher) free(launcherIcon); } g_slist_free(launcher->list_icons); + launcher->list_icons = NULL; free_themes(launcher->list_themes); - launcher->list_icons = NULL; launcher->list_themes = NULL; } diff --git a/src/panel.c b/src/panel.c index c23bf27..f104546 100644 --- a/src/panel.c +++ b/src/panel.c @@ -82,7 +82,7 @@ void default_panel() task_dragged = 0; panel_horizontal = 1; panel_position = CENTER; - panel_items_order = 0; + panel_items_order = NULL; panel_autohide = 0; panel_autohide_show_timeout = 0; panel_autohide_hide_timeout = 0; @@ -106,29 +106,39 @@ void default_panel() void cleanup_panel() { - if (!panel1) return; + if (!panel1) + return; cleanup_taskbar(); - // taskbarname_font_desc freed here because cleanup_taskbarname() called on _NET_NUMBER_OF_DESKTOPS - if (taskbarname_font_desc) pango_font_description_free(taskbarname_font_desc); int i; Panel *p; - for (i=0 ; i < nb_panel ; i++) { + for (i = 0; i < nb_panel; i++) { p = &panel1[i]; free_area(&p->area); - if (p->temp_pmap) XFreePixmap(server.dsp, p->temp_pmap); - if (p->hidden_pixmap) XFreePixmap(server.dsp, p->hidden_pixmap); - if (p->main_win) XDestroyWindow(server.dsp, p->main_win); + if (p->temp_pmap) + XFreePixmap(server.dsp, p->temp_pmap); + p->temp_pmap = 0; + if (p->hidden_pixmap) + XFreePixmap(server.dsp, p->hidden_pixmap); + p->hidden_pixmap = 0; + if (p->main_win) + XDestroyWindow(server.dsp, p->main_win); + p->main_win = 0; } - if (panel_items_order) g_free(panel_items_order); + free(panel_items_order); + panel_items_order = NULL; free(panel_window_name); - if (panel1) free(panel1); + panel_window_name = NULL; + free(panel1); + panel1 = NULL; if (backgrounds) g_array_free(backgrounds, 1); - if (panel_config.g_task.font_desc) pango_font_description_free(panel_config.g_task.font_desc); + backgrounds = NULL; + pango_font_description_free(panel_config.g_task.font_desc); + panel_config.g_task.font_desc = NULL; } void init_panel() @@ -168,7 +178,7 @@ void init_panel() if (panel_config.monitor < 0) p->monitor = i; - if ( p->area.bg == 0 ) + if (!p->area.bg) p->area.bg = &g_array_index(backgrounds, Background, 0); p->area.parent = p; p->area.panel = p; diff --git a/src/panel.h b/src/panel.h index 118677f..3f1c5e1 100644 --- a/src/panel.h +++ b/src/panel.h @@ -68,6 +68,8 @@ extern int max_tick_urgent; extern GArray* backgrounds; extern Imlib_Image default_icon; +// TODO maybe this should be a config option +#define DEFAULT_FONT "sans 10" // tint2 use one panel per monitor and one taskbar per desktop. diff --git a/src/server.c b/src/server.c index 7143e91..0610ed4 100644 --- a/src/server.c +++ b/src/server.c @@ -83,7 +83,7 @@ void server_init_atoms () server.atom.__SWM_VROOT = XInternAtom(server.dsp, "__SWM_VROOT", False); server.atom._MOTIF_WM_HINTS = XInternAtom(server.dsp, "_MOTIF_WM_HINTS", False); server.atom.WM_HINTS = XInternAtom(server.dsp, "WM_HINTS", False); - char *name = g_strdup_printf("_XSETTINGS_S%d", DefaultScreen(server.dsp)); + gchar *name = g_strdup_printf("_XSETTINGS_S%d", DefaultScreen(server.dsp)); server.atom._XSETTINGS_SCREEN = XInternAtom(server.dsp, name, False); g_free(name); server.atom._XSETTINGS_SETTINGS = XInternAtom(server.dsp, "_XSETTINGS_SETTINGS", False); @@ -116,16 +116,24 @@ void server_init_atoms () void cleanup_server() { - if (server.colormap) XFreeColormap(server.dsp, server.colormap); - if (server.colormap32) XFreeColormap(server.dsp, server.colormap32); + if (server.colormap) + XFreeColormap(server.dsp, server.colormap); + server.colormap = 0; + if (server.colormap32) + XFreeColormap(server.dsp, server.colormap32); + server.colormap32 = 0; if (server.monitor) { int i; - for (i=0; iy; server.monitor[i].width = crtc_info->width; server.monitor[i].height = crtc_info->height; - server.monitor[i].names = malloc((crtc_info->noutput+1) * sizeof(char*)); + server.monitor[i].names = malloc((crtc_info->noutput+1) * sizeof(gchar*)); for (j=0; jnoutput; ++j) { XRROutputInfo* output_info = XRRGetOutputInfo(server.dsp, res, crtc_info->outputs[j]); printf("xRandr: Linking output %s with crtc %d\n", output_info->name, i); diff --git a/src/server.h b/src/server.h index 94d2aba..4842604 100644 --- a/src/server.h +++ b/src/server.h @@ -97,7 +97,7 @@ typedef struct Monitor int y; int width; int height; - char** names; + gchar** names; } Monitor; diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index f4637f2..fd88744 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -100,7 +100,7 @@ void init_systray_panel(void *p) { systray.area.parent = p; systray.area.panel = p; - if (systray.area.bg == 0) + if (!systray.area.bg) systray.area.bg = &g_array_index(backgrounds, Background, 0); GSList *l; @@ -308,7 +308,7 @@ void stop_net() remove_icon((TrayWindow*)systray.list_icons->data); g_slist_free(systray.list_icons); - systray.list_icons = 0; + systray.list_icons = NULL; } if (net_sel_win != None) { @@ -501,7 +501,7 @@ void remove_icon(TrayWindow *traywin) // check empty systray int count = 0; GSList *l; - for (l = systray.list_icons; l ; l = l->next) { + for (l = systray.list_icons; l; l = l->next) { if (!((TrayWindow*)l->data)->hide) count++; } diff --git a/src/taskbar/task.c b/src/taskbar/task.c index 1d366d6..da81d82 100644 --- a/src/taskbar/task.c +++ b/src/taskbar/task.c @@ -618,7 +618,7 @@ void add_urgent(Task *tsk) // not yet in the list, so we have to add it urgent_list = g_slist_prepend(urgent_list, tsk); - if (urgent_timeout == 0) + if (!urgent_timeout) urgent_timeout = add_timeout(10, 1000, blink_urgent, 0); Panel *panel = tsk->area.panel; @@ -630,8 +630,8 @@ void add_urgent(Task *tsk) void del_urgent(Task *tsk) { urgent_list = g_slist_remove(urgent_list, tsk); - if (urgent_list == 0) { + if (!urgent_list) { stop_timeout(urgent_timeout); - urgent_timeout = 0; + urgent_timeout = NULL; } } diff --git a/src/taskbar/taskbar.c b/src/taskbar/taskbar.c index 1e369f5..ab7f6f3 100644 --- a/src/taskbar/taskbar.c +++ b/src/taskbar/taskbar.c @@ -55,9 +55,9 @@ void free_ptr_array(gpointer data) { g_ptr_array_free(data, 1); } void default_taskbar() { - win_to_task_table = 0; - urgent_timeout = 0; - urgent_list = 0; + win_to_task_table = NULL; + urgent_timeout = NULL; + urgent_list = NULL; taskbar_enabled = 0; taskbar_distribute_size = 0; hide_inactive_tasks = 0; @@ -78,33 +78,38 @@ void cleanup_taskbar() GHashTableIter iter; gpointer key, value; - g_hash_table_iter_init (&iter, win_to_task_table); - if (g_hash_table_iter_next (&iter, &key, &value)) { + g_hash_table_iter_init(&iter, win_to_task_table); + if (g_hash_table_iter_next(&iter, &key, &value)) { taskbar_remove_task(key, 0, 0); } } + g_hash_table_destroy(win_to_task_table); + win_to_task_table = NULL; } - for (i=0 ; i < nb_panel ; i++) { + for (i = 0 ; i < nb_panel; i++) { panel = &panel1[i]; - for (j=0 ; j < panel->nb_desktop ; j++) { + for (j = 0; j < panel->nb_desktop; j++) { tskbar = &panel->taskbar[j]; - for (k=0; kstate_pix[k]) XFreePixmap(server.dsp, tskbar->state_pix[k]); + for (k = 0; k < TASKBAR_STATE_COUNT; ++k) { + if (tskbar->state_pix[k]) + XFreePixmap(server.dsp, tskbar->state_pix[k]); + tskbar->state_pix[k] = 0; } - free_area (&tskbar->area); + free_area(&tskbar->area); // remove taskbar from the panel panel->area.list = g_slist_remove(panel->area.list, tskbar); } if (panel->taskbar) { free(panel->taskbar); - panel->taskbar = 0; + panel->taskbar = NULL; } } - if (win_to_task_table) { - g_hash_table_destroy(win_to_task_table); - win_to_task_table = 0; - } + g_slist_free(urgent_list); + urgent_list = NULL; + + stop_timeout(urgent_timeout); + urgent_timeout = NULL; } @@ -131,6 +136,8 @@ void init_taskbar_panel(void *p) panel->g_taskbar.background_name[TASKBAR_NORMAL] = &g_array_index(backgrounds, Background, 0); panel->g_taskbar.background_name[TASKBAR_ACTIVE] = &g_array_index(backgrounds, Background, 0); } + if (!panel->g_task.font_desc) + panel->g_task.font_desc = pango_font_description_from_string(DEFAULT_FONT); if (panel->g_task.area.bg == 0) panel->g_task.area.bg = &g_array_index(backgrounds, Background, 0); diff --git a/src/taskbar/taskbar.h b/src/taskbar/taskbar.h index a4bc87f..30093fa 100644 --- a/src/taskbar/taskbar.h +++ b/src/taskbar/taskbar.h @@ -12,7 +12,7 @@ #include "taskbarname.h" enum { TASKBAR_NORMAL, TASKBAR_ACTIVE, TASKBAR_STATE_COUNT }; -extern GHashTable* win_to_task_table; +extern GHashTable *win_to_task_table; extern Task *task_active; extern Task *task_drag; extern int taskbar_enabled; @@ -27,7 +27,7 @@ typedef struct { Area area; Pixmap state_pix[TASKBAR_STATE_COUNT]; - char *name; + gchar *name; int posy; } Taskbarname; diff --git a/src/taskbar/taskbarname.c b/src/taskbar/taskbarname.c index 4f8d19f..84c9070 100644 --- a/src/taskbar/taskbarname.c +++ b/src/taskbar/taskbarname.c @@ -41,7 +41,7 @@ Color taskbarname_active_font; void default_taskbarname() { taskbarname_enabled = 0; - taskbarname_font_desc = 0; + taskbarname_font_desc = NULL; } @@ -51,7 +51,11 @@ void init_taskbarname_panel(void *p) Taskbar *tskbar; int j; - if (!taskbarname_enabled) return; + if (!taskbarname_enabled) + return; + + if (!taskbarname_font_desc) + taskbarname_font_desc = pango_font_description_from_string(DEFAULT_FONT); GSList *l, *list = server_get_name_of_desktop(); for (j=0, l=list ; j < panel->nb_desktop ; j++) { @@ -87,18 +91,24 @@ void cleanup_taskbarname() Panel *panel; Taskbar *tskbar; - for (i=0 ; i < nb_panel ; i++) { + for (i = 0; i < nb_panel; i++) { panel = &panel1[i]; - for (j=0 ; j < panel->nb_desktop ; j++) { + for (j = 0; j < panel->nb_desktop; j++) { tskbar = &panel->taskbar[j]; - if (tskbar->bar_name.name) g_free(tskbar->bar_name.name); - free_area (&tskbar->bar_name.area); - for (k=0; kbar_name.state_pix[k]) XFreePixmap(server.dsp, tskbar->bar_name.state_pix[k]); + g_free(tskbar->bar_name.name); + tskbar->bar_name.name = NULL; + free_area(&tskbar->bar_name.area); + for (k = 0; k < TASKBAR_STATE_COUNT; ++k) { + if (tskbar->bar_name.state_pix[k]) + XFreePixmap(server.dsp, tskbar->bar_name.state_pix[k]); + tskbar->bar_name.state_pix[k] = 0; } tskbar->area.list = g_slist_remove(tskbar->area.list, &tskbar->bar_name); } } + + pango_font_description_free(taskbarname_font_desc); + taskbarname_font_desc = NULL; } diff --git a/src/tint.c b/src/tint.c index 5c24b74..e2788f3 100644 --- a/src/tint.c +++ b/src/tint.c @@ -271,12 +271,15 @@ void cleanup() if (default_icon) { imlib_context_set_image(default_icon); imlib_free_image(); + default_icon = NULL; } imlib_context_disconnect_display(); cleanup_server(); cleanup_timeout(); - if (server.dsp) XCloseDisplay(server.dsp); + if (server.dsp) + XCloseDisplay(server.dsp); + server.dsp = NULL; #ifdef HAVE_SN if (startup_notifications) { diff --git a/src/tooltip/tooltip.c b/src/tooltip/tooltip.c index 65738cc..e1f0ad4 100644 --- a/src/tooltip/tooltip.c +++ b/src/tooltip/tooltip.c @@ -51,17 +51,20 @@ void default_tooltip() void cleanup_tooltip() { stop_tooltip_timeout(); - tooltip_hide(0); - tooltip_copy_text(0); - if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window); - if (g_tooltip.font_desc) pango_font_description_free(g_tooltip.font_desc); + tooltip_hide(NULL); + tooltip_copy_text(NULL); + if (g_tooltip.window) + XDestroyWindow(server.dsp, g_tooltip.window); + g_tooltip.window = 0; + pango_font_description_free(g_tooltip.font_desc); + g_tooltip.font_desc = NULL; } void init_tooltip() { if (!g_tooltip.font_desc) - g_tooltip.font_desc = pango_font_description_from_string("sans 10"); + g_tooltip.font_desc = pango_font_description_from_string(DEFAULT_FONT); if (g_tooltip.bg == 0) g_tooltip.bg = &g_array_index(backgrounds, Background, 0); @@ -72,7 +75,8 @@ void init_tooltip() attr.background_pixel = 0; attr.border_pixel = 0; unsigned long mask = CWEventMask|CWColormap|CWBorderPixel|CWBackPixel|CWOverrideRedirect; - if (g_tooltip.window) XDestroyWindow(server.dsp, g_tooltip.window); + if (g_tooltip.window) + XDestroyWindow(server.dsp, g_tooltip.window); g_tooltip.window = XCreateWindow(server.dsp, server.root_win, 0, 0, 100, 20, 0, server.depth, InputOutput, server.visual, mask, &attr); } @@ -296,10 +300,8 @@ void start_hide_timeout() void stop_tooltip_timeout() { - if (g_tooltip.timeout) { - stop_timeout(g_tooltip.timeout); - g_tooltip.timeout = 0; - } + stop_timeout(g_tooltip.timeout); + g_tooltip.timeout = NULL; } @@ -309,6 +311,6 @@ void tooltip_copy_text(Area* area) if (area && area->_get_tooltip_text) g_tooltip.tooltip_text = strdup(area->_get_tooltip_text(area)); else - g_tooltip.tooltip_text = 0; + g_tooltip.tooltip_text = NULL; g_tooltip.area = area; } diff --git a/src/util/area.c b/src/util/area.c index c1a57e3..20af792 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -456,6 +456,9 @@ void add_area (Area *a) void free_area (Area *a) { + if (!a) + return; + GSList *l0; for (l0 = a->list; l0 ; l0 = l0->next) free_area (l0->data); diff --git a/src/util/timer.c b/src/util/timer.c index 5c70f85..8b0cb5d 100644 --- a/src/util/timer.c +++ b/src/util/timer.c @@ -64,8 +64,8 @@ void stop_multi_timeout(timeout* t); void default_timeout() { - timeout_list = 0; - multi_timeouts = 0; + timeout_list = NULL; + multi_timeouts = NULL; } void cleanup_timeout() @@ -79,7 +79,7 @@ void cleanup_timeout() } if (multi_timeouts) { g_hash_table_destroy(multi_timeouts); - multi_timeouts = 0; + multi_timeouts = NULL; } }