aboutsummaryrefslogtreecommitdiffstats
path: root/swaybar/main.c
diff options
context:
space:
mode:
authorLibravatar progandy <code@progandy>2015-12-22 15:35:37 +0100
committerLibravatar progandy <code@progandy>2015-12-22 17:54:47 +0100
commit8fefdb3c64d53a16bd400f97252c6887f5940af0 (patch)
tree95520c463d91e810fcad8b40b4cb219dfec2e871 /swaybar/main.c
parentswaybar: add a visible separator between elements (diff)
downloadsway-8fefdb3c64d53a16bd400f97252c6887f5940af0.tar.gz
sway-8fefdb3c64d53a16bd400f97252c6887f5940af0.tar.zst
sway-8fefdb3c64d53a16bd400f97252c6887f5940af0.zip
swaybar: fix memory leaks
Diffstat (limited to 'swaybar/main.c')
-rw-r--r--swaybar/main.c40
1 files changed, 38 insertions, 2 deletions
diff --git a/swaybar/main.c b/swaybar/main.c
index a4b757a5..75d043b0 100644
--- a/swaybar/main.c
+++ b/swaybar/main.c
@@ -160,9 +160,21 @@ void cairo_set_source_u32(cairo_t *cairo, uint32_t color) {
160 (color & 0xFF) / 256.0); 160 (color & 0xFF) / 256.0);
161} 161}
162 162
163void free_workspace(void *item) {
164 if (!item) {
165 return;
166 }
167 struct workspace *ws = (struct workspace *)item;
168 if (ws->name) {
169 free(ws->name);
170 }
171 free(ws);
172}
173
163void ipc_update_workspaces() { 174void ipc_update_workspaces() {
164 if (workspaces) { 175 if (workspaces) {
165 free_flat_list(workspaces); 176 list_foreach(workspaces, free_workspace);
177 list_free(workspaces);
166 } 178 }
167 workspaces = create_list(); 179 workspaces = create_list();
168 180
@@ -456,6 +468,29 @@ void render() {
456 } 468 }
457} 469}
458 470
471void free_status_block(void *item) {
472 if (!item) {
473 return;
474 }
475 struct status_block *sb = (struct status_block*)item;
476 if (sb->full_text) {
477 free(sb->full_text);
478 }
479 if (sb->short_text) {
480 free(sb->short_text);
481 }
482 if (sb->align) {
483 free(sb->align);
484 }
485 if (sb->name) {
486 free(sb->name);
487 }
488 if (sb->instance) {
489 free(sb->instance);
490 }
491 free(sb);
492}
493
459void parse_json(const char *text) { 494void parse_json(const char *text) {
460/* the array of objects looks like this: 495/* the array of objects looks like this:
461 * [ { 496 * [ {
@@ -484,7 +519,8 @@ void parse_json(const char *text) {
484 } 519 }
485 520
486 if (status_line) { 521 if (status_line) {
487 free_flat_list(status_line); 522 list_foreach(status_line, free_status_block);
523 list_free(status_line);
488 } 524 }
489 525
490 status_line = create_list(); 526 status_line = create_list();