From 235cfd93b22c24f851d6974a9b56bfe84023ac00 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:00:21 +0100 Subject: 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 61324458..432bee7f 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); -- cgit v1.2.3-54-g00ecf From c225bcaceeda6902a56481962398f5a528bcdf74 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:06:21 +0100 Subject: 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 ebcee95b..06654223 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); } -- cgit v1.2.3-54-g00ecf From cdf017ceea0d09a6d5745c18cc0c8ae6232b49fa Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:07:38 +0100 Subject: 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 06654223..f60decb5 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; } } -- cgit v1.2.3-54-g00ecf From e077ebdc722204bf88072dad376fa1dbe9993c95 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:08:28 +0100 Subject: 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 f60decb5..cfd3fd93 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); } -- cgit v1.2.3-54-g00ecf From b8722ecd5f43c2c6f132809595109e9cb5fbfec6 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:09:56 +0100 Subject: 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 cfd3fd93..41879b87 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; } -- cgit v1.2.3-54-g00ecf From 01c2b5f2d658c8992d5351c1ef0e2e23a0729fcd Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:27:49 +0100 Subject: 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 41879b87..9ce73ceb 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; -- cgit v1.2.3-54-g00ecf From 06986e58b84170f51c4ae303bedb8d8803ed5ba7 Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:31:21 +0100 Subject: 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 9ce73ceb..82215ba5 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; -- cgit v1.2.3-54-g00ecf From e1fa51a152bc417e1085867dc6fc00e197f26a0f Mon Sep 17 00:00:00 2001 From: Daniel Lockyer Date: Fri, 29 Apr 2016 18:36:29 +0100 Subject: 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 82215ba5..f520cc88 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; } } -- cgit v1.2.3-54-g00ecf