summaryrefslogtreecommitdiffstats
path: root/swaybar
diff options
context:
space:
mode:
authorLibravatar emersion <contact@emersion.fr>2018-04-24 22:04:19 +0100
committerLibravatar emersion <contact@emersion.fr>2018-04-24 22:28:55 +0100
commitaa36899d8a54d359bf3da997fb6f681199e49938 (patch)
tree096f6c4635168e71e29e611cebc9afac9e22736b /swaybar
parentMerge pull request #1858 from emersion/master (diff)
downloadsway-aa36899d8a54d359bf3da997fb6f681199e49938.tar.gz
sway-aa36899d8a54d359bf3da997fb6f681199e49938.tar.zst
sway-aa36899d8a54d359bf3da997fb6f681199e49938.zip
Fix a bunch of swaybar memory leaks
Diffstat (limited to 'swaybar')
-rw-r--r--swaybar/bar.c21
-rw-r--r--swaybar/config.c6
-rw-r--r--swaybar/i3bar.c3
-rw-r--r--swaybar/ipc.c13
-rw-r--r--swaybar/status_line.c14
5 files changed, 34 insertions, 23 deletions
diff --git a/swaybar/bar.c b/swaybar/bar.c
index b4c0698f..5b8028e5 100644
--- a/swaybar/bar.c
+++ b/swaybar/bar.c
@@ -25,7 +25,6 @@
25#include "ipc-client.h" 25#include "ipc-client.h"
26#include "list.h" 26#include "list.h"
27#include "log.h" 27#include "log.h"
28#include "pango.h"
29#include "pool-buffer.h" 28#include "pool-buffer.h"
30#include "wlr-layer-shell-unstable-v1-client-protocol.h" 29#include "wlr-layer-shell-unstable-v1-client-protocol.h"
31 30
@@ -34,6 +33,15 @@ static void bar_init(struct swaybar *bar) {
34 wl_list_init(&bar->outputs); 33 wl_list_init(&bar->outputs);
35} 34}
36 35
36void free_workspaces(struct wl_list *list) {
37 struct swaybar_workspace *ws, *tmp;
38 wl_list_for_each_safe(ws, tmp, list, link) {
39 wl_list_remove(&ws->link);
40 free(ws->name);
41 free(ws);
42 }
43}
44
37static void swaybar_output_free(struct swaybar_output *output) { 45static void swaybar_output_free(struct swaybar_output *output) {
38 if (!output) { 46 if (!output) {
39 return; 47 return;
@@ -44,12 +52,7 @@ static void swaybar_output_free(struct swaybar_output *output) {
44 wl_output_destroy(output->output); 52 wl_output_destroy(output->output);
45 destroy_buffer(&output->buffers[0]); 53 destroy_buffer(&output->buffers[0]);
46 destroy_buffer(&output->buffers[1]); 54 destroy_buffer(&output->buffers[1]);
47 struct swaybar_workspace *ws, *ws_tmp; 55 free_workspaces(&output->workspaces);
48 wl_list_for_each_safe(ws, ws_tmp, &output->workspaces, link) {
49 wl_list_remove(&ws->link);
50 free(ws->name);
51 free(ws);
52 }
53 struct swaybar_hotspot *hotspot, *hotspot_tmp; 56 struct swaybar_hotspot *hotspot, *hotspot_tmp;
54 wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) { 57 wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) {
55 if (hotspot->destroy) { 58 if (hotspot->destroy) {
@@ -468,9 +471,7 @@ void bar_run(struct swaybar *bar) {
468static void free_outputs(struct wl_list *list) { 471static void free_outputs(struct wl_list *list) {
469 struct swaybar_output *output, *tmp; 472 struct swaybar_output *output, *tmp;
470 wl_list_for_each_safe(output, tmp, list, link) { 473 wl_list_for_each_safe(output, tmp, list, link) {
471 wl_list_remove(&output->link); 474 swaybar_output_free(output);
472 free(output->name);
473 free(output);
474 } 475 }
475} 476}
476 477
diff --git a/swaybar/config.c b/swaybar/config.c
index 9169ad27..db7b0db6 100644
--- a/swaybar/config.c
+++ b/swaybar/config.c
@@ -74,5 +74,11 @@ void free_config(struct swaybar_config *config) {
74 free(config->font); 74 free(config->font);
75 free(config->mode); 75 free(config->mode);
76 free(config->sep_symbol); 76 free(config->sep_symbol);
77 struct config_output *coutput, *tmp;
78 wl_list_for_each_safe(coutput, tmp, &config->outputs, link) {
79 wl_list_remove(&coutput->link);
80 free(coutput->name);
81 free(coutput);
82 }
77 free(config); 83 free(config);
78} 84}
diff --git a/swaybar/i3bar.c b/swaybar/i3bar.c
index dced13d2..141612a6 100644
--- a/swaybar/i3bar.c
+++ b/swaybar/i3bar.c
@@ -7,7 +7,7 @@
7#include "swaybar/config.h" 7#include "swaybar/config.h"
8#include "swaybar/status_line.h" 8#include "swaybar/status_line.h"
9 9
10static void i3bar_block_free(struct i3bar_block *block) { 10void i3bar_block_free(struct i3bar_block *block) {
11 if (!block) { 11 if (!block) {
12 return; 12 return;
13 } 13 }
@@ -18,6 +18,7 @@ static void i3bar_block_free(struct i3bar_block *block) {
18 free(block->name); 18 free(block->name);
19 free(block->instance); 19 free(block->instance);
20 free(block->color); 20 free(block->color);
21 free(block);
21} 22}
22 23
23static bool i3bar_parse_json(struct status_line *status, const char *text) { 24static bool i3bar_parse_json(struct status_line *status, const char *text) {
diff --git a/swaybar/ipc.c b/swaybar/ipc.c
index ed5d9a31..959fa095 100644
--- a/swaybar/ipc.c
+++ b/swaybar/ipc.c
@@ -216,15 +216,6 @@ static void ipc_parse_config(
216 json_object_put(bar_config); 216 json_object_put(bar_config);
217} 217}
218 218
219static void free_workspaces(struct wl_list *list) {
220 struct swaybar_workspace *ws, *tmp;
221 wl_list_for_each_safe(ws, tmp, list, link) {
222 wl_list_remove(&ws->link);
223 free(ws->name);
224 free(ws);
225 }
226}
227
228void ipc_get_workspaces(struct swaybar *bar) { 219void ipc_get_workspaces(struct swaybar *bar) {
229 bar->focused_output = NULL; 220 bar->focused_output = NULL;
230 struct swaybar_output *output; 221 struct swaybar_output *output;
@@ -290,8 +281,8 @@ static void ipc_get_outputs(struct swaybar *bar) {
290 continue; 281 continue;
291 } 282 }
292 if (bar->config->all_outputs) { 283 if (bar->config->all_outputs) {
293 struct config_output *coutput = calloc( 284 struct config_output *coutput =
294 1, sizeof(struct config_output)); 285 calloc(1, sizeof(struct config_output));
295 coutput->name = strdup(name); 286 coutput->name = strdup(name);
296 coutput->index = i; 287 coutput->index = i;
297 wl_list_insert(&bar->config->outputs, &coutput->link); 288 wl_list_insert(&bar->config->outputs, &coutput->link);
diff --git a/swaybar/status_line.c b/swaybar/status_line.c
index 8d781ca3..e0e7414a 100644
--- a/swaybar/status_line.c
+++ b/swaybar/status_line.c
@@ -1,4 +1,4 @@
1#define _POSIX_C_SOURCE 199309L 1#define _POSIX_C_SOURCE 200809L
2#include <fcntl.h> 2#include <fcntl.h>
3#include <json-c/json.h> 3#include <json-c/json.h>
4#include <stdlib.h> 4#include <stdlib.h>
@@ -126,5 +126,17 @@ void status_line_free(struct status_line *status) {
126 close(status->read_fd); 126 close(status->read_fd);
127 close(status->write_fd); 127 close(status->write_fd);
128 kill(status->pid, SIGTERM); 128 kill(status->pid, SIGTERM);
129 switch (status->protocol) {
130 case PROTOCOL_I3BAR:;
131 struct i3bar_block *block, *tmp;
132 wl_list_for_each_safe(block, tmp, &status->blocks, link) {
133 i3bar_block_free(block);
134 }
135 free(status->i3bar_state.buffer);
136 break;
137 default:
138 free(status->text_state.buffer);
139 break;
140 }
129 free(status); 141 free(status);
130} 142}