]> git.sur5r.net Git - i3/i3/commitdiff
Bugfix: Some memory leaks / invalid accesses
authorMichael Stapelberg <michael+x200@stapelberg.de>
Thu, 5 Mar 2009 00:48:30 +0000 (01:48 +0100)
committerMichael Stapelberg <michael+x200@stapelberg.de>
Thu, 5 Mar 2009 00:48:30 +0000 (01:48 +0100)
src/commands.c
src/handlers.c
src/mainx.c
src/xinerama.c

index 810a04ba32b943a6d3cfdaa6d5a042198bd25796..e2ebcfe1135e9f4ee3caf3ba3dee0601fb683a02 100644 (file)
@@ -323,7 +323,10 @@ static void move_current_window_to_workspace(xcb_connection_t *conn, int workspa
         assert(to_container != NULL);
 
         CIRCLEQ_REMOVE(&(container->clients), current_client, clients);
+        SLIST_REMOVE(&(container->workspace->focus_stack), current_client, Client, focus_clients);
+
         CIRCLEQ_INSERT_TAIL(&(to_container->clients), current_client, clients);
+        SLIST_INSERT_HEAD(&(to_container->workspace->focus_stack), current_client, focus_clients);
         printf("Moved.\n");
 
         current_client->container = to_container;
index 47c1884fee6123ed7e6ca0021335ec8599051191..5c60925614ea19c89ecdd1d772021252cce1e691 100644 (file)
@@ -418,6 +418,18 @@ int handle_unmap_notify_event(void *data, xcb_connection_t *conn, xcb_unmap_noti
                 return 0;
         }
 
+        /* Free the client’s colorpixel cache */
+        struct Colorpixel *colorpixel;
+        while (!SLIST_EMPTY(&(client->colorpixels))) {
+                colorpixel = SLIST_FIRST(&(client->colorpixels));
+                SLIST_REMOVE_HEAD(&(client->colorpixels), colorpixels);
+                free(colorpixel->hex);
+                free(colorpixel);
+        }
+
+        if (client->name != NULL)
+                free(client->name);
+
         if (client->container != NULL) {
                 Container *con = client->container;
 
@@ -474,8 +486,11 @@ int handle_windowname_change(void *data, xcb_connection_t *conn, uint8_t state,
         if (client == NULL)
                 return 1;
 
+        if (client->name != NULL)
+                free(client->name);
+
         client->name_len = xcb_get_property_value_length(prop);
-        client->name = malloc(client->name_len);
+        client->name = smalloc(client->name_len);
         strncpy(client->name, xcb_get_property_value(prop), client->name_len);
         printf("rename to \"%.*s\".\n", client->name_len, client->name);
 
index 83233aeb584b65845c3b422a26e670dfe3ee8a76..a29cd54a2354895bbb3390a0966fac8599216130 100644 (file)
@@ -280,6 +280,7 @@ void manage_existing_windows(xcb_connection_t *conn, xcb_property_handlers_t *pr
         }
 
         free(reply);
+        free(cookies);
 }
 
 int main(int argc, char *argv[], char *env[]) {
index ecc1810c51f1eeb9b3ecda60bcde87b0a9a58d6c..2f5c299bed95c6ba31e71abda78d7346bcbb696d 100644 (file)
@@ -165,12 +165,18 @@ void initialize_xinerama(xcb_connection_t *conn) {
                 return;
         }
 
-        if (!xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL)->state) {
+        xcb_xinerama_is_active_reply_t *reply;
+        reply = xcb_xinerama_is_active_reply(conn, xcb_xinerama_is_active(conn), NULL);
+
+        if (!reply->state) {
                 printf("Xinerama is not active (in your X-Server), disabling.\n");
+                free(reply);
                 disable_xinerama(conn);
                 return;
         }
 
+        free(reply);
+
         query_screens(conn, virtual_screens);
 
         i3Screen *s;
@@ -253,7 +259,8 @@ void xinerama_requery_screens(xcb_connection_t *conn) {
                 }
 
         /* Free the old list */
-        TAILQ_FOREACH(screen, virtual_screens, screens) {
+        while (!TAILQ_EMPTY(virtual_screens)) {
+                screen = TAILQ_FIRST(virtual_screens);
                 TAILQ_REMOVE(virtual_screens, screen, screens);
                 free(screen);
         }