From b3014f7b168eb074bd071ee7cb930d74158a2895 Mon Sep 17 00:00:00 2001 From: frsfnrrg Date: Tue, 17 Jul 2018 10:42:48 -0400 Subject: [PATCH 1/4] Fix uninitialized pointer in view_unmap Otherwise, sway crashes due to uninitialized pointer dereference when AddressSanitizer is active. --- sway/tree/view.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/sway/tree/view.c b/sway/tree/view.c index 70ab93644a..fc31699c18 100644 --- a/sway/tree/view.c +++ b/sway/tree/view.c @@ -621,16 +621,16 @@ void view_unmap(struct sway_view *view) { view->urgent_timer = NULL; } - struct sway_container *parent; struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE); + struct sway_container *parent; if (view->is_fullscreen) { ws->sway_workspace->fullscreen = NULL; parent = container_destroy(view->swayc); arrange_windows(ws->parent); } else { - struct sway_container *parent = container_destroy(view->swayc); + parent = container_destroy(view->swayc); arrange_windows(parent); } if (parent->type >= C_WORKSPACE) { // if the workspace still exists From 600676688a47bde05bc12110818127c5300dd876 Mon Sep 17 00:00:00 2001 From: frsfnrrg Date: Tue, 17 Jul 2018 11:19:32 -0400 Subject: [PATCH 2/4] Free individual criteria in free_config Also free cmd_list when cleaning up a struct criteria. --- sway/config.c | 8 +++++++- sway/criteria.c | 2 +- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sway/config.c b/sway/config.c index 2c05114665..c620e4c756 100644 --- a/sway/config.c +++ b/sway/config.c @@ -24,6 +24,7 @@ #include "sway/input/seat.h" #include "sway/commands.h" #include "sway/config.h" +#include "sway/criteria.h" #include "sway/tree/arrange.h" #include "sway/tree/layout.h" #include "sway/tree/workspace.h" @@ -105,7 +106,12 @@ void free_config(struct sway_config *config) { } list_free(config->seat_configs); } - list_free(config->criteria); + if (config->criteria) { + for (int i = 0; i < config->criteria->length; ++i) { + criteria_destroy(config->criteria->items[i]); + } + list_free(config->criteria); + } list_free(config->no_focus); list_free(config->active_bar_modifiers); list_free(config->config_chain); diff --git a/sway/criteria.c b/sway/criteria.c index c999d24880..e2b248de55 100644 --- a/sway/criteria.c +++ b/sway/criteria.c @@ -37,7 +37,7 @@ void criteria_destroy(struct criteria *criteria) { pcre_free(criteria->con_mark); pcre_free(criteria->window_role); free(criteria->workspace); - + free(criteria->cmdlist); free(criteria->raw); free(criteria); } From 37471ac649cf594975b4e0ab09291c116c66feec Mon Sep 17 00:00:00 2001 From: frsfnrrg Date: Tue, 17 Jul 2018 11:21:32 -0400 Subject: [PATCH 3/4] Fix memory leak in handle_layer_shell_surface --- sway/desktop/layer_shell.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/sway/desktop/layer_shell.c b/sway/desktop/layer_shell.c index 91baa6f820..a7d9671702 100644 --- a/sway/desktop/layer_shell.c +++ b/sway/desktop/layer_shell.c @@ -325,12 +325,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { layer_surface->client_pending.margin.bottom, layer_surface->client_pending.margin.left); - struct sway_layer_surface *sway_layer = - calloc(1, sizeof(struct sway_layer_surface)); - if (!sway_layer) { - return; - } - if (!layer_surface->output) { // Assign last active output struct sway_container *output = NULL; @@ -352,6 +346,12 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) { layer_surface->output = output->sway_output->wlr_output; } + struct sway_layer_surface *sway_layer = + calloc(1, sizeof(struct sway_layer_surface)); + if (!sway_layer) { + return; + } + sway_layer->surface_commit.notify = handle_surface_commit; wl_signal_add(&layer_surface->surface->events.commit, &sway_layer->surface_commit); From 3931cb85b220294764db959513ecadb893e2c47b Mon Sep 17 00:00:00 2001 From: frsfnrrg Date: Tue, 17 Jul 2018 11:22:38 -0400 Subject: [PATCH 4/4] Fix memory leak in sway/desktop/idle_inhibit_v1.c --- sway/desktop/idle_inhibit_v1.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/desktop/idle_inhibit_v1.c b/sway/desktop/idle_inhibit_v1.c index 108a841776..da17d0f216 100644 --- a/sway/desktop/idle_inhibit_v1.c +++ b/sway/desktop/idle_inhibit_v1.c @@ -67,6 +67,7 @@ struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create( manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display); if (!manager->wlr_manager) { + free(manager); return NULL; } manager->idle = idle;