Fix a bunch of swaybar memory leaks

This commit is contained in:
emersion 2018-04-24 22:04:19 +01:00
parent 317b8cbd93
commit aa36899d8a
No known key found for this signature in database
GPG key ID: 0FDE7BE0E88F5E48
8 changed files with 38 additions and 24 deletions

View file

@ -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);
}
}