aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--common/list.c24
-rw-r--r--common/loop.c6
-rw-r--r--common/stringop.c8
-rw-r--r--include/list.h7
-rw-r--r--include/stringop.h3
-rw-r--r--sway/commands.c3
-rw-r--r--sway/commands/bar/modifier.c5
-rw-r--r--sway/commands/bind.c16
-rw-r--r--sway/commands/reload.c7
-rw-r--r--sway/commands/workspace.c2
-rw-r--r--sway/config.c19
-rw-r--r--sway/config/bar.c7
-rw-r--r--sway/config/seat.c5
-rw-r--r--sway/ipc-server.c7
-rw-r--r--sway/main.c5
-rw-r--r--sway/tree/container.c8
-rw-r--r--sway/tree/workspace.c2
-rw-r--r--swayidle/main.c19
-rw-r--r--swaynag/swaynag.c5
-rw-r--r--swaynag/types.c6
20 files changed, 64 insertions, 100 deletions
diff --git a/common/list.c b/common/list.c
index 66cf133b..c3e2fe20 100644
--- a/common/list.c
+++ b/common/list.c
@@ -30,15 +30,6 @@ void list_free(list_t *list) {
30 free(list); 30 free(list);
31} 31}
32 32
33void list_foreach(list_t *list, void (*callback)(void *item)) {
34 if (list == NULL || callback == NULL) {
35 return;
36 }
37 for (int i = 0; i < list->length; i++) {
38 callback(list->items[i]);
39 }
40}
41
42void list_add(list_t *list, void *item) { 33void list_add(list_t *list, void *item) {
43 list_resize(list); 34 list_resize(list);
44 list->items[list->length++] = item; 35 list->items[list->length++] = item;
@@ -57,8 +48,7 @@ void list_del(list_t *list, int index) {
57} 48}
58 49
59void list_cat(list_t *list, list_t *source) { 50void list_cat(list_t *list, list_t *source) {
60 int i; 51 for (int i = 0; i < source->length; ++i) {
61 for (i = 0; i < source->length; ++i) {
62 list_add(list, source->items[i]); 52 list_add(list, source->items[i]);
63 } 53 }
64} 54}
@@ -156,3 +146,15 @@ void list_stable_sort(list_t *list, int compare(const void *a, const void *b)) {
156 list_inplace_sort(list, 0, list->length - 1, compare); 146 list_inplace_sort(list, 0, list->length - 1, compare);
157 } 147 }
158} 148}
149
150void list_free_items_and_destroy(list_t *list) {
151 if (!list) {
152 return;
153 }
154
155 for (int i = 0; i < list->length; ++i) {
156 free(list->items[i]);
157 }
158 list_free(list);
159}
160
diff --git a/common/loop.c b/common/loop.c
index 82b80017..295f3a30 100644
--- a/common/loop.c
+++ b/common/loop.c
@@ -45,10 +45,8 @@ struct loop *loop_create(void) {
45} 45}
46 46
47void loop_destroy(struct loop *loop) { 47void loop_destroy(struct loop *loop) {
48 list_foreach(loop->fd_events, free); 48 list_free_items_and_destroy(loop->fd_events);
49 list_foreach(loop->timers, free); 49 list_free_items_and_destroy(loop->timers);
50 list_free(loop->fd_events);
51 list_free(loop->timers);
52 free(loop->fds); 50 free(loop->fds);
53 free(loop); 51 free(loop);
54} 52}
diff --git a/common/stringop.c b/common/stringop.c
index df016e9d..4b8c9a38 100644
--- a/common/stringop.c
+++ b/common/stringop.c
@@ -97,14 +97,6 @@ list_t *split_string(const char *str, const char *delims) {
97 return res; 97 return res;
98} 98}
99 99
100void free_flat_list(list_t *list) {
101 int i;
102 for (i = 0; i < list->length; ++i) {
103 free(list->items[i]);
104 }
105 list_free(list);
106}
107
108char **split_args(const char *start, int *argc) { 100char **split_args(const char *start, int *argc) {
109 *argc = 0; 101 *argc = 0;
110 int alloc = 2; 102 int alloc = 2;
diff --git a/include/list.h b/include/list.h
index 03851a82..895f6cc0 100644
--- a/include/list.h
+++ b/include/list.h
@@ -9,7 +9,6 @@ typedef struct {
9 9
10list_t *create_list(void); 10list_t *create_list(void);
11void list_free(list_t *list); 11void list_free(list_t *list);
12void list_foreach(list_t *list, void (*callback)(void* item));
13void list_add(list_t *list, void *item); 12void list_add(list_t *list, void *item);
14void list_insert(list_t *list, int index, void *item); 13void list_insert(list_t *list, int index, void *item);
15void list_del(list_t *list, int index); 14void list_del(list_t *list, int index);
@@ -27,4 +26,10 @@ void list_stable_sort(list_t *list, int compare(const void *a, const void *b));
27void list_swap(list_t *list, int src, int dest); 26void list_swap(list_t *list, int src, int dest);
28// move item to end of list 27// move item to end of list
29void list_move_to_end(list_t *list, void *item); 28void list_move_to_end(list_t *list, void *item);
29
30/* Calls `free` for each item in the list, then frees the list.
31 * Do not use this to free lists of primitives or items that require more
32 * complicated deallocation code.
33 */
34void list_free_items_and_destroy(list_t *list);
30#endif 35#endif
diff --git a/include/stringop.h b/include/stringop.h
index 919e605c..d1bfa29d 100644
--- a/include/stringop.h
+++ b/include/stringop.h
@@ -17,9 +17,8 @@ char *lenient_strncat(char *dest, const char *src, size_t len);
17// strcmp that also handles null pointers. 17// strcmp that also handles null pointers.
18int lenient_strcmp(char *a, char *b); 18int lenient_strcmp(char *a, char *b);
19 19
20// Simply split a string with delims, free with `free_flat_list` 20// Simply split a string with delims, free with `list_free_items_and_destroy`
21list_t *split_string(const char *str, const char *delims); 21list_t *split_string(const char *str, const char *delims);
22void free_flat_list(list_t *list);
23 22
24// Splits an argument string, keeping quotes intact 23// Splits an argument string, keeping quotes intact
25char **split_args(const char *str, int *argc); 24char **split_args(const char *str, int *argc);
diff --git a/sway/commands.c b/sway/commands.c
index d5cab655..f6d1cc3e 100644
--- a/sway/commands.c
+++ b/sway/commands.c
@@ -43,8 +43,7 @@ struct cmd_results *checkarg(int argc, const char *name, enum expected_args type
43} 43}
44 44
45void apply_seat_config(struct seat_config *seat_config) { 45void apply_seat_config(struct seat_config *seat_config) {
46 int i; 46 int i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
47 i = list_seq_find(config->seat_configs, seat_name_cmp, seat_config->name);
48 if (i >= 0) { 47 if (i >= 0) {
49 // merge existing config 48 // merge existing config
50 struct seat_config *sc = config->seat_configs->items[i]; 49 struct seat_config *sc = config->seat_configs->items[i];
diff --git a/sway/commands/bar/modifier.c b/sway/commands/bar/modifier.c
index 09025fff..b5a16f45 100644
--- a/sway/commands/bar/modifier.c
+++ b/sway/commands/bar/modifier.c
@@ -20,15 +20,14 @@ struct cmd_results *bar_cmd_modifier(int argc, char **argv) {
20 uint32_t tmp_mod; 20 uint32_t tmp_mod;
21 if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) { 21 if ((tmp_mod = get_modifier_mask_by_name(split->items[i])) > 0) {
22 mod |= tmp_mod; 22 mod |= tmp_mod;
23 continue;
24 } else { 23 } else {
25 error = cmd_results_new(CMD_INVALID, "modifier", 24 error = cmd_results_new(CMD_INVALID, "modifier",
26 "Unknown modifier '%s'", split->items[i]); 25 "Unknown modifier '%s'", split->items[i]);
27 free_flat_list(split); 26 list_free_items_and_destroy(split);
28 return error; 27 return error;
29 } 28 }
30 } 29 }
31 free_flat_list(split); 30 list_free_items_and_destroy(split);
32 config->current_bar->modifier = mod; 31 config->current_bar->modifier = mod;
33 wlr_log(WLR_DEBUG, 32 wlr_log(WLR_DEBUG,
34 "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]); 33 "Show/Hide the bar when pressing '%s' in hide mode.", argv[0]);
diff --git a/sway/commands/bind.c b/sway/commands/bind.c
index c8b634b9..01a35cf2 100644
--- a/sway/commands/bind.c
+++ b/sway/commands/bind.c
@@ -23,9 +23,7 @@ void free_sway_binding(struct sway_binding *binding) {
23 return; 23 return;
24 } 24 }
25 25
26 if (binding->keys) { 26 list_free_items_and_destroy(binding->keys);
27 free_flat_list(binding->keys);
28 }
29 free(binding->input); 27 free(binding->input);
30 free(binding->command); 28 free(binding->command);
31 free(binding); 29 free(binding);
@@ -80,7 +78,6 @@ static int key_qsort_cmp(const void *keyp_a, const void *keyp_b) {
80 return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0); 78 return (key_a < key_b) ? -1 : ((key_a > key_b) ? 1 : 0);
81} 79}
82 80
83
84/** 81/**
85 * From a keycode, bindcode, or bindsym name and the most likely binding type, 82 * From a keycode, bindcode, or bindsym name and the most likely binding type,
86 * identify the appropriate numeric value corresponding to the key. Return NULL 83 * identify the appropriate numeric value corresponding to the key. Return NULL
@@ -223,14 +220,14 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
223 uint32_t *key = calloc(1, sizeof(uint32_t)); 220 uint32_t *key = calloc(1, sizeof(uint32_t));
224 if (!key) { 221 if (!key) {
225 free_sway_binding(binding); 222 free_sway_binding(binding);
226 free_flat_list(split); 223 list_free_items_and_destroy(split);
227 return cmd_results_new(CMD_FAILURE, bindtype, 224 return cmd_results_new(CMD_FAILURE, bindtype,
228 "Unable to allocate binding key"); 225 "Unable to allocate binding key");
229 } 226 }
230 *key = key_val; 227 *key = key_val;
231 list_add(binding->keys, key); 228 list_add(binding->keys, key);
232 } 229 }
233 free_flat_list(split); 230 list_free_items_and_destroy(split);
234 binding->order = binding_order++; 231 binding->order = binding_order++;
235 232
236 // refine region of interest for mouse binding once we are certain 233 // refine region of interest for mouse binding once we are certain
@@ -280,7 +277,6 @@ static struct cmd_results *cmd_bindsym_or_bindcode(int argc, char **argv,
280 wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'", 277 wlr_log(WLR_DEBUG, "%s - Bound %s to command `%s` for device '%s'",
281 bindtype, argv[0], binding->command, binding->input); 278 bindtype, argv[0], binding->command, binding->input);
282 return cmd_results_new(CMD_SUCCESS, NULL, NULL); 279 return cmd_results_new(CMD_SUCCESS, NULL, NULL);
283
284} 280}
285 281
286struct cmd_results *cmd_bindsym(int argc, char **argv) { 282struct cmd_results *cmd_bindsym(int argc, char **argv) {
@@ -291,7 +287,6 @@ struct cmd_results *cmd_bindcode(int argc, char **argv) {
291 return cmd_bindsym_or_bindcode(argc, argv, true); 287 return cmd_bindsym_or_bindcode(argc, argv, true);
292} 288}
293 289
294
295/** 290/**
296 * Execute the command associated to a binding 291 * Execute the command associated to a binding
297 */ 292 */
@@ -301,15 +296,14 @@ void seat_execute_command(struct sway_seat *seat, struct sway_binding *binding)
301 config->handler_context.seat = seat; 296 config->handler_context.seat = seat;
302 list_t *res_list = execute_command(binding->command, NULL, NULL); 297 list_t *res_list = execute_command(binding->command, NULL, NULL);
303 bool success = true; 298 bool success = true;
304 while (res_list->length) { 299 for (int i = 0; i < res_list->length; ++i) {
305 struct cmd_results *results = res_list->items[0]; 300 struct cmd_results *results = res_list->items[i];
306 if (results->status != CMD_SUCCESS) { 301 if (results->status != CMD_SUCCESS) {
307 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)", 302 wlr_log(WLR_DEBUG, "could not run command for binding: %s (%s)",
308 binding->command, results->error); 303 binding->command, results->error);
309 success = false; 304 success = false;
310 } 305 }
311 free_cmd_results(results); 306 free_cmd_results(results);
312 list_del(res_list, 0);
313 } 307 }
314 list_free(res_list); 308 list_free(res_list);
315 if (success) { 309 if (success) {
diff --git a/sway/commands/reload.c b/sway/commands/reload.c
index c64de4bd..3ccbbf34 100644
--- a/sway/commands/reload.c
+++ b/sway/commands/reload.c
@@ -24,8 +24,7 @@ static void do_reload(void *data) {
24 24
25 if (!load_main_config(config->current_config_path, true, false)) { 25 if (!load_main_config(config->current_config_path, true, false)) {
26 wlr_log(WLR_ERROR, "Error(s) reloading config"); 26 wlr_log(WLR_ERROR, "Error(s) reloading config");
27 list_foreach(bar_ids, free); 27 list_free_items_and_destroy(bar_ids);
28 list_free(bar_ids);
29 return; 28 return;
30 } 29 }
31 30
@@ -42,9 +41,7 @@ static void do_reload(void *data) {
42 } 41 }
43 } 42 }
44 } 43 }
45 44 list_free_items_and_destroy(bar_ids);
46 list_foreach(bar_ids, free);
47 list_free(bar_ids);
48 45
49 config_update_font_height(true); 46 config_update_font_height(true);
50 root_for_each_container(rebuild_textures_iterator, NULL); 47 root_for_each_container(rebuild_textures_iterator, NULL);
diff --git a/sway/commands/workspace.c b/sway/commands/workspace.c
index 7d32e65b..211b344d 100644
--- a/sway/commands/workspace.c
+++ b/sway/commands/workspace.c
@@ -33,7 +33,7 @@ static struct workspace_config *workspace_config_find_or_create(char *ws_name) {
33 33
34void free_workspace_config(struct workspace_config *wsc) { 34void free_workspace_config(struct workspace_config *wsc) {
35 free(wsc->workspace); 35 free(wsc->workspace);
36 free_flat_list(wsc->outputs); 36 list_free_items_and_destroy(wsc->outputs);
37 free(wsc); 37 free(wsc);
38} 38}
39 39
diff --git a/sway/config.c b/sway/config.c
index ff7de4b9..5b03bc56 100644
--- a/sway/config.c
+++ b/sway/config.c
@@ -38,26 +38,24 @@
38struct sway_config *config = NULL; 38struct sway_config *config = NULL;
39 39
40static void free_mode(struct sway_mode *mode) { 40static void free_mode(struct sway_mode *mode) {
41 int i;
42
43 if (!mode) { 41 if (!mode) {
44 return; 42 return;
45 } 43 }
46 free(mode->name); 44 free(mode->name);
47 if (mode->keysym_bindings) { 45 if (mode->keysym_bindings) {
48 for (i = 0; i < mode->keysym_bindings->length; i++) { 46 for (int i = 0; i < mode->keysym_bindings->length; i++) {
49 free_sway_binding(mode->keysym_bindings->items[i]); 47 free_sway_binding(mode->keysym_bindings->items[i]);
50 } 48 }
51 list_free(mode->keysym_bindings); 49 list_free(mode->keysym_bindings);
52 } 50 }
53 if (mode->keycode_bindings) { 51 if (mode->keycode_bindings) {
54 for (i = 0; i < mode->keycode_bindings->length; i++) { 52 for (int i = 0; i < mode->keycode_bindings->length; i++) {
55 free_sway_binding(mode->keycode_bindings->items[i]); 53 free_sway_binding(mode->keycode_bindings->items[i]);
56 } 54 }
57 list_free(mode->keycode_bindings); 55 list_free(mode->keycode_bindings);
58 } 56 }
59 if (mode->mouse_bindings) { 57 if (mode->mouse_bindings) {
60 for (i = 0; i < mode->mouse_bindings->length; i++) { 58 for (int i = 0; i < mode->mouse_bindings->length; i++) {
61 free_sway_binding(mode->mouse_bindings->items[i]); 59 free_sway_binding(mode->mouse_bindings->items[i]);
62 } 60 }
63 list_free(mode->mouse_bindings); 61 list_free(mode->mouse_bindings);
@@ -446,7 +444,7 @@ bool load_main_config(const char *file, bool is_active, bool validating) {
446 } 444 }
447 } 445 }
448 446
449 free_flat_list(secconfigs); 447 list_free_items_and_destroy(secconfigs);
450 } 448 }
451 */ 449 */
452 450
@@ -654,8 +652,7 @@ bool read_config(FILE *file, struct sway_config *config,
654 652
655 if (read + length > config_size) { 653 if (read + length > config_size) {
656 wlr_log(WLR_ERROR, "Config file changed during reading"); 654 wlr_log(WLR_ERROR, "Config file changed during reading");
657 list_foreach(stack, free); 655 list_free_items_and_destroy(stack);
658 list_free(stack);
659 free(line); 656 free(line);
660 return false; 657 return false;
661 } 658 }
@@ -684,8 +681,7 @@ bool read_config(FILE *file, struct sway_config *config,
684 } 681 }
685 char *expanded = expand_line(block, line, brace_detected > 0); 682 char *expanded = expand_line(block, line, brace_detected > 0);
686 if (!expanded) { 683 if (!expanded) {
687 list_foreach(stack, free); 684 list_free_items_and_destroy(stack);
688 list_free(stack);
689 free(line); 685 free(line);
690 return false; 686 return false;
691 } 687 }
@@ -750,8 +746,7 @@ bool read_config(FILE *file, struct sway_config *config,
750 free(line); 746 free(line);
751 free_cmd_results(res); 747 free_cmd_results(res);
752 } 748 }
753 list_foreach(stack, free); 749 list_free_items_and_destroy(stack);
754 list_free(stack);
755 config->current_config_line_number = 0; 750 config->current_config_line_number = 0;
756 config->current_config_line = NULL; 751 config->current_config_line = NULL;
757 752
diff --git a/sway/config/bar.c b/sway/config/bar.c
index 36e10527..45c9e998 100644
--- a/sway/config/bar.c
+++ b/sway/config/bar.c
@@ -49,13 +49,10 @@ void free_bar_config(struct bar_config *bar) {
49 free(bar->font); 49 free(bar->font);
50 free(bar->separator_symbol); 50 free(bar->separator_symbol);
51 for (int i = 0; i < bar->bindings->length; i++) { 51 for (int i = 0; i < bar->bindings->length; i++) {
52 struct bar_binding *binding = bar->bindings->items[i]; 52 free_bar_binding(bar->bindings->items[i]);
53 free_bar_binding(binding);
54 } 53 }
55 list_free(bar->bindings); 54 list_free(bar->bindings);
56 if (bar->outputs) { 55 list_free_items_and_destroy(bar->outputs);
57 free_flat_list(bar->outputs);
58 }
59 if (bar->pid != 0) { 56 if (bar->pid != 0) {
60 terminate_swaybar(bar->pid); 57 terminate_swaybar(bar->pid);
61 } 58 }
diff --git a/sway/config/seat.c b/sway/config/seat.c
index 56fa6095..1cb4c363 100644
--- a/sway/config/seat.c
+++ b/sway/config/seat.c
@@ -117,11 +117,8 @@ void free_seat_config(struct seat_config *seat) {
117 117
118 free(seat->name); 118 free(seat->name);
119 for (int i = 0; i < seat->attachments->length; ++i) { 119 for (int i = 0; i < seat->attachments->length; ++i) {
120 struct seat_attachment_config *attachment = 120 seat_attachment_config_free(seat->attachments->items[i]);
121 seat->attachments->items[i];
122 seat_attachment_config_free(attachment);
123 } 121 }
124
125 list_free(seat->attachments); 122 list_free(seat->attachments);
126 free(seat); 123 free(seat);
127} 124}
diff --git a/sway/ipc-server.c b/sway/ipc-server.c
index b3954259..2c642a37 100644
--- a/sway/ipc-server.c
+++ b/sway/ipc-server.c
@@ -73,14 +73,11 @@ static void handle_display_destroy(struct wl_listener *listener, void *data) {
73 unlink(ipc_sockaddr->sun_path); 73 unlink(ipc_sockaddr->sun_path);
74 74
75 while (ipc_client_list->length) { 75 while (ipc_client_list->length) {
76 struct ipc_client *client = ipc_client_list->items[0]; 76 ipc_client_disconnect(ipc_client_list->items[ipc_client_list->length-1]);
77 ipc_client_disconnect(client);
78 } 77 }
79 list_free(ipc_client_list); 78 list_free(ipc_client_list);
80 79
81 if (ipc_sockaddr) { 80 free(ipc_sockaddr);
82 free(ipc_sockaddr);
83 }
84 81
85 wl_list_remove(&ipc_display_destroy.link); 82 wl_list_remove(&ipc_display_destroy.link);
86} 83}
diff --git a/sway/main.c b/sway/main.c
index a74183fe..f70e751d 100644
--- a/sway/main.c
+++ b/sway/main.c
@@ -393,13 +393,12 @@ int main(int argc, char **argv) {
393 while (config->cmd_queue->length) { 393 while (config->cmd_queue->length) {
394 char *line = config->cmd_queue->items[0]; 394 char *line = config->cmd_queue->items[0];
395 list_t *res_list = execute_command(line, NULL, NULL); 395 list_t *res_list = execute_command(line, NULL, NULL);
396 while (res_list->length) { 396 for (int i = 0; i < res_list->length; ++i) {
397 struct cmd_results *res = res_list->items[0]; 397 struct cmd_results *res = res_list->items[i];
398 if (res->status != CMD_SUCCESS) { 398 if (res->status != CMD_SUCCESS) {
399 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error); 399 wlr_log(WLR_ERROR, "Error on line '%s': %s", line, res->error);
400 } 400 }
401 free_cmd_results(res); 401 free_cmd_results(res);
402 list_del(res_list, 0);
403 } 402 }
404 list_free(res_list); 403 list_free(res_list);
405 free(line); 404 free(line);
diff --git a/sway/tree/container.c b/sway/tree/container.c
index 91e8dd7f..b106e0d9 100644
--- a/sway/tree/container.c
+++ b/sway/tree/container.c
@@ -21,6 +21,7 @@
21#include "sway/tree/arrange.h" 21#include "sway/tree/arrange.h"
22#include "sway/tree/view.h" 22#include "sway/tree/view.h"
23#include "sway/tree/workspace.h" 23#include "sway/tree/workspace.h"
24#include "list.h"
24#include "log.h" 25#include "log.h"
25#include "stringop.h" 26#include "stringop.h"
26 27
@@ -67,8 +68,7 @@ void container_destroy(struct sway_container *con) {
67 list_free(con->current.children); 68 list_free(con->current.children);
68 list_free(con->outputs); 69 list_free(con->outputs);
69 70
70 list_foreach(con->marks, free); 71 list_free_items_and_destroy(con->marks);
71 list_free(con->marks);
72 wlr_texture_destroy(con->marks_focused); 72 wlr_texture_destroy(con->marks_focused);
73 wlr_texture_destroy(con->marks_focused_inactive); 73 wlr_texture_destroy(con->marks_focused_inactive);
74 wlr_texture_destroy(con->marks_unfocused); 74 wlr_texture_destroy(con->marks_unfocused);
@@ -1267,7 +1267,9 @@ bool container_find_and_unmark(char *mark) {
1267} 1267}
1268 1268
1269void container_clear_marks(struct sway_container *con) { 1269void container_clear_marks(struct sway_container *con) {
1270 list_foreach(con->marks, free); 1270 for (int i = 0; i < con->marks->length; ++i) {
1271 free(con->marks->items[i]);
1272 }
1271 con->marks->length = 0; 1273 con->marks->length = 0;
1272 ipc_event_window(con, "mark"); 1274 ipc_event_window(con, "mark");
1273} 1275}
diff --git a/sway/tree/workspace.c b/sway/tree/workspace.c
index 4be63311..ed24b4fd 100644
--- a/sway/tree/workspace.c
+++ b/sway/tree/workspace.c
@@ -142,7 +142,7 @@ void workspace_destroy(struct sway_workspace *workspace) {
142 142
143 free(workspace->name); 143 free(workspace->name);
144 free(workspace->representation); 144 free(workspace->representation);
145 free_flat_list(workspace->output_priority); 145 list_free_items_and_destroy(workspace->output_priority);
146 list_free(workspace->floating); 146 list_free(workspace->floating);
147 list_free(workspace->tiling); 147 list_free(workspace->tiling);
148 list_free(workspace->current.floating); 148 list_free(workspace->current.floating);
diff --git a/swayidle/main.c b/swayidle/main.c
index dd7d9de3..9a76e58c 100644
--- a/swayidle/main.c
+++ b/swayidle/main.c
@@ -365,11 +365,6 @@ static int parse_args(int argc, char *argv[]) {
365 return 0; 365 return 0;
366} 366}
367 367
368static void register_zero_idle_timeout(void *item) {
369 struct swayidle_timeout_cmd *cmd = item;
370 register_timeout(cmd, 0);
371}
372
373static int handle_signal(int sig, void *data) { 368static int handle_signal(int sig, void *data) {
374 switch (sig) { 369 switch (sig) {
375 case SIGINT: 370 case SIGINT:
@@ -378,7 +373,9 @@ static int handle_signal(int sig, void *data) {
378 return 0; 373 return 0;
379 case SIGUSR1: 374 case SIGUSR1:
380 wlr_log(WLR_DEBUG, "Got SIGUSR1"); 375 wlr_log(WLR_DEBUG, "Got SIGUSR1");
381 list_foreach(state.timeout_cmds, register_zero_idle_timeout); 376 for (int i = 0; i < state.timeout_cmds->length; ++i) {
377 register_timeout(state.timeout_cmds->items[i], 0);
378 }
382 return 1; 379 return 1;
383 } 380 }
384 assert(false); // not reached 381 assert(false); // not reached
@@ -409,11 +406,6 @@ static int display_event(int fd, uint32_t mask, void *data) {
409 return count; 406 return count;
410} 407}
411 408
412static void register_idle_timeout(void *item) {
413 struct swayidle_timeout_cmd *cmd = item;
414 register_timeout(cmd, cmd->timeout);
415}
416
417int main(int argc, char *argv[]) { 409int main(int argc, char *argv[]) {
418 if (parse_args(argc, argv) != 0) { 410 if (parse_args(argc, argv) != 0) {
419 return -1; 411 return -1;
@@ -458,7 +450,10 @@ int main(int argc, char *argv[]) {
458 sway_terminate(0); 450 sway_terminate(0);
459 } 451 }
460 452
461 list_foreach(state.timeout_cmds, register_idle_timeout); 453 for (int i = 0; i < state.timeout_cmds->length; ++i) {
454 struct swayidle_timeout_cmd *cmd = state.timeout_cmds->items[i];
455 register_timeout(cmd, cmd->timeout);
456 }
462 457
463 wl_display_roundtrip(state.display); 458 wl_display_roundtrip(state.display);
464 459
diff --git a/swaynag/swaynag.c b/swaynag/swaynag.c
index a2a0b412..e6dfd25f 100644
--- a/swaynag/swaynag.c
+++ b/swaynag/swaynag.c
@@ -407,9 +407,8 @@ void swaynag_destroy(struct swaynag *swaynag) {
407 swaynag->run_display = false; 407 swaynag->run_display = false;
408 408
409 free(swaynag->message); 409 free(swaynag->message);
410 while (swaynag->buttons->length) { 410 for (int i = 0; i < swaynag->buttons->length; ++i) {
411 struct swaynag_button *button = swaynag->buttons->items[0]; 411 struct swaynag_button *button = swaynag->buttons->items[i];
412 list_del(swaynag->buttons, 0);
413 free(button->text); 412 free(button->text);
414 free(button->action); 413 free(button->action);
415 free(button); 414 free(button);
diff --git a/swaynag/types.c b/swaynag/types.c
index 129644b7..bc17bd33 100644
--- a/swaynag/types.c
+++ b/swaynag/types.c
@@ -147,10 +147,8 @@ void swaynag_type_free(struct swaynag_type *type) {
147} 147}
148 148
149void swaynag_types_free(list_t *types) { 149void swaynag_types_free(list_t *types) {
150 while (types->length) { 150 for (int i = 0; i < types->length; ++i) {
151 struct swaynag_type *type = types->items[0]; 151 swaynag_type_free(types->items[i]);
152 swaynag_type_free(type);
153 list_del(types, 0);
154 } 152 }
155 list_free(types); 153 list_free(types);
156} 154}