Fix some memory leaks (issue #641)

This commit is contained in:
o9000
2017-04-30 20:49:08 +02:00
parent 6df4eb4bee
commit 380f260027
2 changed files with 44 additions and 40 deletions

View File

@@ -158,6 +158,29 @@ Task *add_task(Window win)
return (Task *)g_ptr_array_index(task_buttons, 0); return (Task *)g_ptr_array_index(task_buttons, 0);
} }
void task_remove_icon(Task *task)
{
if (!task)
return;
for (int k = 0; k < TASK_STATE_COUNT; ++k) {
if (task->icon[k]) {
imlib_context_set_image(task->icon[k]);
imlib_free_image();
task->icon[k] = 0;
}
if (task->icon_hover[k]) {
imlib_context_set_image(task->icon_hover[k]);
imlib_free_image();
task->icon_hover[k] = 0;
}
if (task->icon_press[k]) {
imlib_context_set_image(task->icon_press[k]);
imlib_free_image();
task->icon_press[k] = 0;
}
}
}
void remove_task(Task *task) void remove_task(Task *task)
{ {
if (!task) if (!task)
@@ -178,23 +201,7 @@ void remove_task(Task *task)
// printf("remove_task %s %d\n", task->title, task->desktop); // printf("remove_task %s %d\n", task->title, task->desktop);
if (task->title) if (task->title)
free(task->title); free(task->title);
for (int k = 0; k < TASK_STATE_COUNT; ++k) { task_remove_icon(task);
if (task->icon[k]) {
imlib_context_set_image(task->icon[k]);
imlib_free_image();
task->icon[k] = 0;
}
if (task->icon_hover[k]) {
imlib_context_set_image(task->icon_hover[k]);
imlib_free_image();
task->icon_hover[k] = 0;
}
if (task->icon_press[k]) {
imlib_context_set_image(task->icon_press[k]);
imlib_free_image();
task->icon_press[k] = 0;
}
}
GPtrArray *task_buttons = g_hash_table_lookup(win_to_task, &win); GPtrArray *task_buttons = g_hash_table_lookup(win_to_task, &win);
for (int i = 0; i < task_buttons->len; ++i) { for (int i = 0; i < task_buttons->len; ++i) {
@@ -265,20 +272,15 @@ void task_update_icon(Task *task)
if (!panel->g_task.has_icon) if (!panel->g_task.has_icon)
return; return;
for (int k = 0; k < TASK_STATE_COUNT; ++k) { task_remove_icon(task);
if (task->icon[k]) {
imlib_context_set_image(task->icon[k]);
imlib_free_image();
task->icon[k] = 0;
}
}
Imlib_Image img = NULL; Imlib_Image img = NULL;
if (!img) { if (!img) {
int len; int len;
gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &len); gulong *data = server_get_property(task->win, server.atom._NET_WM_ICON, XA_CARDINAL, &len);
if (data && len > 0) { if (data) {
if (len > 0) {
// get ARGB icon // get ARGB icon
int w, h; int w, h;
gulong *tmp_data = get_best_icon(data, get_icon_count(data, len), len, &w, &h, panel->g_task.icon_size1); gulong *tmp_data = get_best_icon(data, get_icon_count(data, len), len, &w, &h, panel->g_task.icon_size1);
@@ -295,6 +297,7 @@ void task_update_icon(Task *task)
h, h,
task->title ? task->title : "task"); task->title ? task->title : "task");
} }
}
XFree(data); XFree(data);
} }
} }

View File

@@ -652,6 +652,7 @@ void cleanup()
cleanup_server(); cleanup_server();
cleanup_timeout(); cleanup_timeout();
if (server.display) if (server.display)
XCloseDisplay(server.display); XCloseDisplay(server.display);
server.display = NULL; server.display = NULL;