Skip to content

Commit

Permalink
Merge pull request #2289 from frsfnrrg/memory-fixes
Browse files Browse the repository at this point in the history
Fix memory leaks and reference to uninitialized
  • Loading branch information
ddevault authored Jul 17, 2018
2 parents f516dbf + 3931cb8 commit bec982b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
8 changes: 7 additions & 1 deletion sway/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion sway/criteria.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
1 change: 1 addition & 0 deletions sway/desktop/idle_inhibit_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 6 additions & 6 deletions sway/desktop/layer_shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions sway/tree/view.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bec982b

Please sign in to comment.