From 235cfd93b22c24f851d6974a9b56bfe84023ac00 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:00:21 +0100 Subject: [PATCH 1/8] common/stringop.c: a premature decrement meant an element of argv was never released --- common/stringop.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/stringop.c b/common/stringop.c index 613244585..432bee7ff 100644 --- a/common/stringop.c +++ b/common/stringop.c @@ -144,7 +144,7 @@ char **split_args(const char *start, int *argc) { } void free_argv(int argc, char **argv) { - while (--argc > 0) { + while (argc-- > 0) { free(argv[argc]); } free(argv); From c225bcaceeda6902a56481962398f5a528bcdf74 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:06:21 +0100 Subject: [PATCH 2/8] sway/config.c: config_home is the result of a malloc but was never freed --- sway/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/config.c b/sway/config.c index ebcee95be..06654223f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -267,6 +267,7 @@ static char *get_config_path(void) { strcpy(config_home, home); strcat(config_home, "/.config"); setenv("XDG_CONFIG_HOME", config_home, 1); + free(config_home); sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); } From cdf017ceea0d09a6d5745c18cc0c8ae6232b49fa Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:07:38 +0100 Subject: [PATCH 3/8] sway/config.c: wordexp has a corresponding wordfree which was never used I had to change the assignment to path to be wrapped by strdup as we pass the data out of the method. --- sway/config.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 06654223f..f60decb51 100644 --- a/sway/config.c +++ b/sway/config.c @@ -277,8 +277,9 @@ static char *get_config_path(void) { int i; for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) { if (wordexp(config_paths[i], &p, 0) == 0) { - path = p.we_wordv[0]; + path = strdup(p.we_wordv[0]); if (file_exists(path)) { + wordfree(&p); return path; } } From e077ebdc722204bf88072dad376fa1dbe9993c95 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:08:28 +0100 Subject: [PATCH 4/8] sway/config.c: res->input is a malloc'ed section which wasn't freed --- sway/config.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sway/config.c b/sway/config.c index f60decb51..cfd3fd93f 100644 --- a/sway/config.c +++ b/sway/config.c @@ -534,6 +534,7 @@ bool read_config(FILE *file, struct sway_config *config) { default:; } free(line); + free(res->input); free(res); } From b8722ecd5f43c2c6f132809595109e9cb5fbfec6 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:09:56 +0100 Subject: [PATCH 5/8] sway/config.c: Leading on from cdf017c, we need to free path --- sway/config.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sway/config.c b/sway/config.c index cfd3fd93f..41879b874 100644 --- a/sway/config.c +++ b/sway/config.c @@ -357,6 +357,8 @@ bool load_main_config(const char *file, bool is_active) { update_active_bar_modifiers(); } + free(path); + return success; } From 01c2b5f2d658c8992d5351c1ef0e2e23a0729fcd Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:27:49 +0100 Subject: [PATCH 6/8] sway/config.c: move free call to after sway_log --- sway/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 41879b874..9ce73ceba 100644 --- a/sway/config.c +++ b/sway/config.c @@ -267,8 +267,8 @@ static char *get_config_path(void) { strcpy(config_home, home); strcat(config_home, "/.config"); setenv("XDG_CONFIG_HOME", config_home, 1); - free(config_home); sway_log(L_DEBUG, "Set XDG_CONFIG_HOME to %s", config_home); + free(config_home); } wordexp_t p; From 06986e58b84170f51c4ae303bedb8d8803ed5ba7 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:31:21 +0100 Subject: [PATCH 7/8] sway/config.c: Change to the useful free_cmd_results helper method --- sway/config.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sway/config.c b/sway/config.c index 9ce73ceba..82215ba50 100644 --- a/sway/config.c +++ b/sway/config.c @@ -536,8 +536,7 @@ bool read_config(FILE *file, struct sway_config *config) { default:; } free(line); - free(res->input); - free(res); + free_cmd_results(res); } return success; From e1fa51a152bc417e1085867dc6fc00e197f26a0f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:36:29 +0100 Subject: [PATCH 8/8] sway/config.c: Move the wordfree call before the if statement so it is always called --- sway/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sway/config.c b/sway/config.c index 82215ba50..f520cc889 100644 --- a/sway/config.c +++ b/sway/config.c @@ -278,8 +278,8 @@ static char *get_config_path(void) { for (i = 0; i < (int)(sizeof(config_paths) / sizeof(char *)); ++i) { if (wordexp(config_paths[i], &p, 0) == 0) { path = strdup(p.we_wordv[0]); + wordfree(&p); if (file_exists(path)) { - wordfree(&p); return path; } }