From fcf27bee908a5384316bef111bf42cc595e5e717 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=A9mie=20Galarneau?= Date: Thu, 22 Apr 2021 14:47:14 -0400 Subject: [PATCH] Fix: sessiond: leak of config_path on duplicate --config option MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 1452207 Resource leak The system resource will not be reclaimed and reused, reducing the future availability of the resource. CID 1452373 (#3 of 3): Resource leak (RESOURCE_LEAK) 26. overwrite_var: Overwriting config_path in config_path = utils_expand_path(optarg) leaks the storage that config_path points to. Reported-by: Coverity Scan Signed-off-by: Jérémie Galarneau Change-Id: I70eff0f4de5ac9b84b699e88232669259eab54db --- src/bin/lttng-sessiond/main.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index de95fad31..1174162aa 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -856,7 +856,7 @@ static int set_options(int argc, char **argv) int ret = 0, c = 0, option_index = 0; int orig_optopt = optopt, orig_optind = optind; char *optstring; - const char *config_path = NULL; + char *config_path = NULL; optstring = utils_generate_optstring(long_options, sizeof(long_options) / sizeof(struct option)); @@ -880,6 +880,7 @@ static int set_options(int argc, char **argv) WARN("Getting '%s' argument from setuid/setgid binary refused for security reasons.", "-f, --config"); } else { + free(config_path); config_path = utils_expand_path(optarg); if (!config_path) { ERR("Failed to resolve path: %s", optarg); @@ -925,6 +926,7 @@ static int set_options(int argc, char **argv) } end: + free(config_path); free(optstring); return ret; } -- 2.34.1