From aa36899d8a54d359bf3da997fb6f681199e49938 Mon Sep 17 00:00:00 2001 From: emersion Date: Tue, 24 Apr 2018 22:04:19 +0100 Subject: Fix a bunch of swaybar memory leaks --- swaybar/bar.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'swaybar/bar.c') 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 @@ #include "ipc-client.h" #include "list.h" #include "log.h" -#include "pango.h" #include "pool-buffer.h" #include "wlr-layer-shell-unstable-v1-client-protocol.h" @@ -34,6 +33,15 @@ static void bar_init(struct swaybar *bar) { wl_list_init(&bar->outputs); } +void free_workspaces(struct wl_list *list) { + struct swaybar_workspace *ws, *tmp; + wl_list_for_each_safe(ws, tmp, list, link) { + wl_list_remove(&ws->link); + free(ws->name); + free(ws); + } +} + static void swaybar_output_free(struct swaybar_output *output) { if (!output) { return; @@ -44,12 +52,7 @@ static void swaybar_output_free(struct swaybar_output *output) { wl_output_destroy(output->output); destroy_buffer(&output->buffers[0]); destroy_buffer(&output->buffers[1]); - struct swaybar_workspace *ws, *ws_tmp; - wl_list_for_each_safe(ws, ws_tmp, &output->workspaces, link) { - wl_list_remove(&ws->link); - free(ws->name); - free(ws); - } + free_workspaces(&output->workspaces); struct swaybar_hotspot *hotspot, *hotspot_tmp; wl_list_for_each_safe(hotspot, hotspot_tmp, &output->hotspots, link) { if (hotspot->destroy) { @@ -468,9 +471,7 @@ void bar_run(struct swaybar *bar) { static void free_outputs(struct wl_list *list) { struct swaybar_output *output, *tmp; wl_list_for_each_safe(output, tmp, list, link) { - wl_list_remove(&output->link); - free(output->name); - free(output); + swaybar_output_free(output); } } -- cgit v1.2.3-70-g09d2