From 1343b77dbbee7464714fd4c33b02ca7ff9693d2b Mon Sep 17 00:00:00 2001 From: Michael Stapelberg Date: Thu, 5 Mar 2009 01:48:30 +0100 Subject: [PATCH] Bugfix: Some memory leaks / invalid accesses --- src/commands.c | 3 +++ src/handlers.c | 17 ++++++++++++++++- src/mainx.c | 1 + src/xinerama.c | 11 +++++++++-- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/commands.c b/src/commands.c index 810a04ba..e2ebcfe1 100644 --- a/src/commands.c +++ b/src/commands.c @@ -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; diff --git a/src/handlers.c b/src/handlers.c index 47c1884f..5c609256 100644 --- a/src/handlers.c +++ b/src/handlers.c @@ -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); diff --git a/src/mainx.c b/src/mainx.c index 83233aeb..a29cd54a 100644 --- a/src/mainx.c +++ b/src/mainx.c @@ -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[]) { diff --git a/src/xinerama.c b/src/xinerama.c index ecc1810c..2f5c299b 100644 --- a/src/xinerama.c +++ b/src/xinerama.c @@ -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); } -- 2.39.5