From afca73b6fc799790a1e4c4f103788c357ebecb74 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 29 Dec 2017 11:25:07 +0100 Subject: [PATCH 1/5] apply_input_config: restore previous `current_input_config` This is important for freeing the proper one at end of block --- sway/commands.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sway/commands.c b/sway/commands.c index b0078a46..b7432bf6 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -70,8 +70,10 @@ void apply_input_config(struct input_config *input) { list_add(config->input_configs, input); } + struct input_config *old_input_config = current_input_config; current_input_config = input; sway_input_manager_apply_input_config(input_manager, input); + current_input_config = old_input_config; } void apply_seat_config(struct seat_config *seat) { From 28b8ea9f1ee57672f39e42521f6ed2aece0d3b2e Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 29 Dec 2017 11:28:10 +0100 Subject: [PATCH 2/5] cmd_input: cleanup around current_input_config - Restore old one if we weren't part of a block (should be NULL anyway) - Check current_input_config got properly allocated - free temporary current_input_config when done using it --- sway/commands/input.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/sway/commands/input.c b/sway/commands/input.c index ccb1d276..edf45e4c 100644 --- a/sway/commands/input.c +++ b/sway/commands/input.c @@ -24,7 +24,11 @@ struct cmd_results *cmd_input(int argc, char **argv) { char **argv_new = argv+2; struct cmd_results *res; + struct input_config *old_input_config = current_input_config; current_input_config = new_input_config(argv[0]); + if (!current_input_config) { + return cmd_results_new(CMD_FAILURE, NULL, "Couldn't allocate config"); + } if (strcasecmp("accel_profile", argv[1]) == 0) { res = input_cmd_accel_profile(argc_new, argv_new); } else if (strcasecmp("click_method", argv[1]) == 0) { @@ -60,6 +64,7 @@ struct cmd_results *cmd_input(int argc, char **argv) { } else { res = cmd_results_new(CMD_INVALID, "input ", "Unknown command %s", argv[1]); } - current_input_config = NULL; + free_input_config(current_input_config); + current_input_config = old_input_config; return res; } From f5b33cb4b62438bd084505ec0632bc7dbedc0acd Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 29 Dec 2017 11:29:13 +0100 Subject: [PATCH 3/5] fix typos in comments/messages; add shutting down message --- sway/commands.c | 2 +- sway/config.c | 2 +- sway/main.c | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/sway/commands.c b/sway/commands.c index b7432bf6..c1c6dc5d 100644 --- a/sway/commands.c +++ b/sway/commands.c @@ -197,7 +197,7 @@ static struct cmd_handler *find_handler(char *line, enum cmd_status block) { struct cmd_results *handle_command(char *_exec) { // Even though this function will process multiple commands we will only // return the last error, if any (for now). (Since we have access to an - // error string we could e.g. concatonate all errors there.) + // error string we could e.g. concatenate all errors there.) struct cmd_results *results = NULL; char *exec = strdup(_exec); char *head = exec; diff --git a/sway/config.c b/sway/config.c index 312e0779..53a54a07 100644 --- a/sway/config.c +++ b/sway/config.c @@ -446,7 +446,7 @@ bool read_config(FILE *file, struct sway_config *config) { break; case CMD_DEFER: - sway_log(L_DEBUG, "Defferring command `%s'", line); + sway_log(L_DEBUG, "Deferring command `%s'", line); list_add(config->cmd_queue, strdup(line)); break; diff --git a/sway/main.c b/sway/main.c index c18e2677..f2f24be3 100644 --- a/sway/main.c +++ b/sway/main.c @@ -380,7 +380,7 @@ int main(int argc, char **argv) { // prevent ipc from crashing sway signal(SIGPIPE, SIG_IGN); - wlr_log(L_INFO, "Starting sway version " SWAY_VERSION "\n"); + wlr_log(L_INFO, "Starting sway version " SWAY_VERSION); init_layout(); @@ -414,6 +414,8 @@ int main(int argc, char **argv) { server_run(&server); } + wlr_log(L_INFO, "Shutting down sway"); + server_fini(&server); ipc_terminate(); From 9a326be7f881f8589049a517b9e3112b562d81ea Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 29 Dec 2017 11:31:08 +0100 Subject: [PATCH 4/5] config: leak sanitizer pass Add free for everything that's implemented right now. Will need to add more as the implementations are re-added. --- sway/config.c | 75 ++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 74 insertions(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 53a54a07..37f6e75a 100644 --- a/sway/config.c +++ b/sway/config.c @@ -31,8 +31,79 @@ struct sway_config *config = NULL; +static void free_binding(struct sway_binding *bind) { + if (!bind) { + return; + } + free_flat_list(bind->keys); + free(bind->command); + free(bind); +} + +static void free_mode(struct sway_mode *mode) { + int i; + + if (!mode) { + return; + } + free(mode->name); + if (mode->keysym_bindings) { + for (i = 0; i < mode->keysym_bindings->length; i++) { + free_binding(mode->keysym_bindings->items[i]); + } + list_free(mode->keysym_bindings); + } + if (mode->keycode_bindings) { + for (i = 0; i < mode->keycode_bindings->length; i++) { + free_binding(mode->keycode_bindings->items[i]); + } + list_free(mode->keycode_bindings); + } + free(mode); +} + void free_config(struct sway_config *config) { - // TODO + int i; + + if (!config) { + return; + } + + // TODO: handle all currently unhandled lists as we add implementations + list_free(config->symbols); + if (config->modes) { + for (i = 0; i < config->modes->length; i++) { + free_mode(config->modes->items[i]); + } + list_free(config->modes); + } + list_free(config->bars); + list_free(config->cmd_queue); + list_free(config->workspace_outputs); + list_free(config->pid_workspaces); + list_free(config->output_configs); + if (config->input_configs) { + for (i = 0; i < config->input_configs->length; i++) { + free_input_config(config->input_configs->items[i]); + } + list_free(config->input_configs); + } + list_free(config->seat_configs); + list_free(config->criteria); + list_free(config->no_focus); + list_free(config->active_bar_modifiers); + list_free(config->config_chain); + list_free(config->command_policies); + list_free(config->feature_policies); + list_free(config->ipc_policies); + free(config->current_bar); + free(config->floating_scroll_up_cmd); + free(config->floating_scroll_down_cmd); + free(config->floating_scroll_left_cmd); + free(config->floating_scroll_right_cmd); + free(config->font); + free((char *)config->current_config); + free(config); } static void config_defaults(struct sway_config *config) { @@ -186,6 +257,7 @@ static char *get_config_path(void) { if (file_exists(path)) { return path; } + free(path); } } @@ -524,6 +596,7 @@ bool read_config(FILE *file, struct sway_config *config) { case CMD_BLOCK_INPUT: sway_log(L_DEBUG, "End of input block"); + free_input_config(current_input_config); current_input_config = NULL; block = CMD_BLOCK_END; break; From 19ddb70a3296a7cc3256be65c488c18d87de4261 Mon Sep 17 00:00:00 2001 From: Dominique Martinet Date: Fri, 29 Dec 2017 14:44:39 +0100 Subject: [PATCH 5/5] fixup free config use free_sway_binding --- sway/config.c | 13 ++----------- 1 file changed, 2 insertions(+), 11 deletions(-) diff --git a/sway/config.c b/sway/config.c index 37f6e75a..627ed94f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -31,15 +31,6 @@ struct sway_config *config = NULL; -static void free_binding(struct sway_binding *bind) { - if (!bind) { - return; - } - free_flat_list(bind->keys); - free(bind->command); - free(bind); -} - static void free_mode(struct sway_mode *mode) { int i; @@ -49,13 +40,13 @@ static void free_mode(struct sway_mode *mode) { free(mode->name); if (mode->keysym_bindings) { for (i = 0; i < mode->keysym_bindings->length; i++) { - free_binding(mode->keysym_bindings->items[i]); + free_sway_binding(mode->keysym_bindings->items[i]); } list_free(mode->keysym_bindings); } if (mode->keycode_bindings) { for (i = 0; i < mode->keycode_bindings->length; i++) { - free_binding(mode->keycode_bindings->items[i]); + free_sway_binding(mode->keycode_bindings->items[i]); } list_free(mode->keycode_bindings); }