diff options
author | progandy <code@progandy> | 2015-12-22 15:35:37 +0100 |
---|---|---|
committer | progandy <code@progandy> | 2015-12-22 17:54:47 +0100 |
commit | 8fefdb3c64d53a16bd400f97252c6887f5940af0 (patch) | |
tree | 95520c463d91e810fcad8b40b4cb219dfec2e871 /swaybar | |
parent | d060d0a39f977cf4e74fe3d9a747ee717ad733ba (diff) | |
download | sway-8fefdb3c64d53a16bd400f97252c6887f5940af0.tar.xz |
swaybar: fix memory leaks
Diffstat (limited to 'swaybar')
-rw-r--r-- | swaybar/main.c | 40 |
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) { (color & 0xFF) / 256.0); } +void free_workspace(void *item) { + if (!item) { + return; + } + struct workspace *ws = (struct workspace *)item; + if (ws->name) { + free(ws->name); + } + free(ws); +} + void ipc_update_workspaces() { if (workspaces) { - free_flat_list(workspaces); + list_foreach(workspaces, free_workspace); + list_free(workspaces); } workspaces = create_list(); @@ -456,6 +468,29 @@ void render() { } } +void free_status_block(void *item) { + if (!item) { + return; + } + struct status_block *sb = (struct status_block*)item; + if (sb->full_text) { + free(sb->full_text); + } + if (sb->short_text) { + free(sb->short_text); + } + if (sb->align) { + free(sb->align); + } + if (sb->name) { + free(sb->name); + } + if (sb->instance) { + free(sb->instance); + } + free(sb); +} + void parse_json(const char *text) { /* the array of objects looks like this: * [ { @@ -484,7 +519,8 @@ void parse_json(const char *text) { } if (status_line) { - free_flat_list(status_line); + list_foreach(status_line, free_status_block); + list_free(status_line); } status_line = create_list(); |