]> git.sur5r.net Git - i3/i3/commitdiff
fix memory leak when swallowing windows
authorMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Jan 2016 15:47:48 +0000 (16:47 +0100)
committerMichael Stapelberg <michael@stapelberg.de>
Sat, 9 Jan 2016 16:06:58 +0000 (17:06 +0100)
include/window.h
src/manage.c
src/tree.c
src/window.c

index 7a248277abd09cf92fa564998f07602544d066f9..d0b97f1dfee238343af53f75ea2c9f4fe6c6eab8 100644 (file)
@@ -9,6 +9,12 @@
  */
 #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
  * given window.
index 8e68c51eef17909d8314435d51b09ee85a3af29e..2bcb47f3684b2683a6dead59fc8fce3b6037a586 100644 (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;
     x_reinit(nc);
 
index 5ff426cad60b96e00ff25d2c685174e9f24443a2..0c301209e7ec6efdf6afe9767ddabb7cb7d85c25 100644 (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);
         }
         ipc_send_window_event("close", con);
-        FREE(con->window->class_class);
-        FREE(con->window->class_instance);
-        i3string_free(con->window->name);
-        FREE(con->window->ran_assignments);
-        FREE(con->window);
+        window_free(con->window);
+        con->window = NULL;
     }
 
     Con *ws = con_get_workspace(con);
index bd4e2719b2319b7912f118be8cab90012a50b804..d6136c788039f50d0a5131b83bfc9855c5af3eb7 100644 (file)
  */
 #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
  * given window.