From: Andreas Fink Date: Tue, 5 Jan 2010 11:21:18 +0000 (+0000) Subject: *fix* memleak X-Git-Url: https://git.dogcows.com/gitweb?a=commitdiff_plain;h=643543c7ff5dd2f0552ed20c98b2ced0490771c6;p=chaz%2Ftint2 *fix* memleak *fix* issue 192 --- diff --git a/src/config.c b/src/config.c index d5f7ef1..69ceda0 100644 --- a/src/config.c +++ b/src/config.c @@ -66,6 +66,7 @@ static int old_config_file; // temporary list of background static GSList *list_back; +static int back_count; @@ -73,6 +74,7 @@ void init_config() { // append full transparency background list_back = g_slist_append(0, calloc(1, sizeof(Area))); + back_count = 1; // tint2 could reload config, so we cleanup objects cleanup_systray(); @@ -192,6 +194,7 @@ void add_entry (char *key, char *value) Area *a = calloc(1, sizeof(Area)); a->pix.border.rounded = atoi (value); list_back = g_slist_append(list_back, a); + back_count++; } else if (strcmp (key, "border_width") == 0) { Area *a = g_slist_last(list_back)->data; @@ -284,6 +287,7 @@ void add_entry (char *key, char *value) panel_config.g_task.font_shadow = atoi (value); else if (strcmp (key, "panel_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.area.pix.border, &a->pix.border, sizeof(Border)); @@ -357,6 +361,7 @@ void add_entry (char *key, char *value) else if (strcmp (key, "battery_background_id") == 0) { #ifdef ENABLE_BATTERY int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.battery.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.battery.area.pix.border, &a->pix.border, sizeof(Border)); @@ -402,6 +407,7 @@ void add_entry (char *key, char *value) } else if (strcmp (key, "clock_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.clock.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.clock.area.pix.border, &a->pix.border, sizeof(Border)); @@ -436,12 +442,14 @@ void add_entry (char *key, char *value) } else if (strcmp (key, "taskbar_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.g_taskbar.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.g_taskbar.pix.border, &a->pix.border, sizeof(Border)); } else if (strcmp (key, "taskbar_active_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.g_taskbar.pix_active.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.g_taskbar.pix_active.border, &a->pix.border, sizeof(Border)); @@ -502,12 +510,14 @@ void add_entry (char *key, char *value) } else if (strcmp (key, "task_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.g_task.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.g_task.area.pix.border, &a->pix.border, sizeof(Border)); } else if (strcmp (key, "task_active_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&panel_config.g_task.area.pix_active.back, &a->pix.back, sizeof(Color)); memcpy(&panel_config.g_task.area.pix_active.border, &a->pix.border, sizeof(Border)); @@ -529,6 +539,7 @@ void add_entry (char *key, char *value) } else if (strcmp (key, "systray_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&systray.area.pix.back, &a->pix.back, sizeof(Color)); memcpy(&systray.area.pix.border, &a->pix.border, sizeof(Border)); @@ -571,6 +582,7 @@ void add_entry (char *key, char *value) } else if (strcmp (key, "tooltip_background_id") == 0) { int id = atoi (value); + id = id < back_count ? id : 0; Area *a = g_slist_nth_data(list_back, id); memcpy(&g_tooltip.background_color, &a->pix.back, sizeof(Color)); memcpy(&g_tooltip.border, &a->pix.border, sizeof(Border)); diff --git a/src/systray/systraybar.c b/src/systray/systraybar.c index dbe2c82..f551623 100644 --- a/src/systray/systraybar.c +++ b/src/systray/systraybar.c @@ -516,7 +516,7 @@ void systray_render_icons(TrayWindow* traywin) render_image(panel->main_win, traywin->x, traywin->y, traywin->width, traywin->height); render_image(systray.area.pix.pmap, traywin->x-systray.area.posx, traywin->y-systray.area.posy, traywin->width, traywin->height); } - imlib_free_image(); + imlib_free_image_and_decache(); } diff --git a/src/util/area.c b/src/util/area.c index 3fb1116..acce725 100644 --- a/src/util/area.c +++ b/src/util/area.c @@ -256,4 +256,5 @@ void clear_pixmap(Pixmap p, int x, int y, int w, int h) Picture pict = XRenderCreatePicture(server.dsp, p, XRenderFindVisualFormat(server.dsp, server.visual), 0, 0); XRenderColor col = { .red=0, .green=0, .blue=0, .alpha=0 }; XRenderFillRectangle(server.dsp, PictOpSrc, pict, &col, x, y, w, h); + XRenderFreePicture(server.dsp, pict); }