Skip to content

Commit bec982b

Browse files
authored
Merge pull request #2289 from frsfnrrg/memory-fixes
Fix memory leaks and reference to uninitialized
2 parents f516dbf + 3931cb8 commit bec982b

File tree

5 files changed

+17
-10
lines changed

5 files changed

+17
-10
lines changed

sway/config.c

+7-1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "sway/input/seat.h"
2525
#include "sway/commands.h"
2626
#include "sway/config.h"
27+
#include "sway/criteria.h"
2728
#include "sway/tree/arrange.h"
2829
#include "sway/tree/layout.h"
2930
#include "sway/tree/workspace.h"
@@ -105,7 +106,12 @@ void free_config(struct sway_config *config) {
105106
}
106107
list_free(config->seat_configs);
107108
}
108-
list_free(config->criteria);
109+
if (config->criteria) {
110+
for (int i = 0; i < config->criteria->length; ++i) {
111+
criteria_destroy(config->criteria->items[i]);
112+
}
113+
list_free(config->criteria);
114+
}
109115
list_free(config->no_focus);
110116
list_free(config->active_bar_modifiers);
111117
list_free(config->config_chain);

sway/criteria.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void criteria_destroy(struct criteria *criteria) {
3737
pcre_free(criteria->con_mark);
3838
pcre_free(criteria->window_role);
3939
free(criteria->workspace);
40-
40+
free(criteria->cmdlist);
4141
free(criteria->raw);
4242
free(criteria);
4343
}

sway/desktop/idle_inhibit_v1.c

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ struct sway_idle_inhibit_manager_v1 *sway_idle_inhibit_manager_v1_create(
6767

6868
manager->wlr_manager = wlr_idle_inhibit_v1_create(wl_display);
6969
if (!manager->wlr_manager) {
70+
free(manager);
7071
return NULL;
7172
}
7273
manager->idle = idle;

sway/desktop/layer_shell.c

+6-6
Original file line numberDiff line numberDiff line change
@@ -325,12 +325,6 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
325325
layer_surface->client_pending.margin.bottom,
326326
layer_surface->client_pending.margin.left);
327327

328-
struct sway_layer_surface *sway_layer =
329-
calloc(1, sizeof(struct sway_layer_surface));
330-
if (!sway_layer) {
331-
return;
332-
}
333-
334328
if (!layer_surface->output) {
335329
// Assign last active output
336330
struct sway_container *output = NULL;
@@ -352,6 +346,12 @@ void handle_layer_shell_surface(struct wl_listener *listener, void *data) {
352346
layer_surface->output = output->sway_output->wlr_output;
353347
}
354348

349+
struct sway_layer_surface *sway_layer =
350+
calloc(1, sizeof(struct sway_layer_surface));
351+
if (!sway_layer) {
352+
return;
353+
}
354+
355355
sway_layer->surface_commit.notify = handle_surface_commit;
356356
wl_signal_add(&layer_surface->surface->events.commit,
357357
&sway_layer->surface_commit);

sway/tree/view.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -621,16 +621,16 @@ void view_unmap(struct sway_view *view) {
621621
view->urgent_timer = NULL;
622622
}
623623

624-
struct sway_container *parent;
625624
struct sway_container *ws = container_parent(view->swayc, C_WORKSPACE);
626625

626+
struct sway_container *parent;
627627
if (view->is_fullscreen) {
628628
ws->sway_workspace->fullscreen = NULL;
629629
parent = container_destroy(view->swayc);
630630

631631
arrange_windows(ws->parent);
632632
} else {
633-
struct sway_container *parent = container_destroy(view->swayc);
633+
parent = container_destroy(view->swayc);
634634
arrange_windows(parent);
635635
}
636636
if (parent->type >= C_WORKSPACE) { // if the workspace still exists

0 commit comments

Comments
 (0)