fix memory leak when swallowing windows

This commit is contained in:
Michael Stapelberg 2016-01-09 16:47:48 +01:00
parent 8d917497c2
commit f511cc61c1
4 changed files with 23 additions and 5 deletions

View File

@ -9,6 +9,12 @@
*/ */
#pragma once #pragma once
/**
* Frees an i3Window and all its members.
*
*/
void window_free(i3Window *win);
/** /**
* Updates the WM_CLASS (consisting of the class and instance) for the * Updates the WM_CLASS (consisting of the class and instance) for the
* given window. * given window.

View File

@ -310,6 +310,9 @@ void manage_window(xcb_window_t window, xcb_get_window_attributes_cookie_t cooki
} }
} }
} }
if (nc->window != cwindow && nc->window != NULL) {
window_free(nc->window);
}
nc->window = cwindow; nc->window = cwindow;
x_reinit(nc); x_reinit(nc);

View File

@ -266,11 +266,8 @@ bool tree_close_internal(Con *con, kill_window_t kill_window, bool dont_kill_par
add_ignore_event(cookie.sequence, 0); add_ignore_event(cookie.sequence, 0);
} }
ipc_send_window_event("close", con); ipc_send_window_event("close", con);
FREE(con->window->class_class); window_free(con->window);
FREE(con->window->class_instance); con->window = NULL;
i3string_free(con->window->name);
FREE(con->window->ran_assignments);
FREE(con->window);
} }
Con *ws = con_get_workspace(con); Con *ws = con_get_workspace(con);

View File

@ -11,6 +11,18 @@
*/ */
#include "all.h" #include "all.h"
/*
* Frees an i3Window and all its members.
*
*/
void window_free(i3Window *win) {
FREE(win->class_class);
FREE(win->class_instance);
i3string_free(win->name);
FREE(win->ran_assignments);
FREE(win);
}
/* /*
* Updates the WM_CLASS (consisting of the class and instance) for the * Updates the WM_CLASS (consisting of the class and instance) for the
* given window. * given window.