From: Jérémie Galarneau Date: Mon, 20 Aug 2018 19:50:48 +0000 (-0400) Subject: Fix: clean-up sessiond condig structure on initialization error X-Git-Tag: v2.11.0-rc1~143 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=c9a2957d9bca98ac11384b1e25c75a529ad1ee52;p=lttng-tools.git Fix: clean-up sessiond condig structure on initialization error The sessiond configuration structure's initialization may fail, leaving some fields allocated and others to NULL. On error, the structure should be cleaned-up to prevent a leak. This allows the rest of the code to assume that all configuration options are not NULL. Signed-off-by: Jérémie Galarneau --- diff --git a/src/bin/lttng-sessiond/main.c b/src/bin/lttng-sessiond/main.c index e8f05cecf..6d3ae1b58 100644 --- a/src/bin/lttng-sessiond/main.c +++ b/src/bin/lttng-sessiond/main.c @@ -591,15 +591,9 @@ static void sessiond_cleanup(void) */ utils_close_pipe(thread_quit_pipe); - /* - * If config.pid_file_path.value is undefined, the default file will be - * wiped when removing the rundir. - */ - if (config.pid_file_path.value) { - ret = remove(config.pid_file_path.value); - if (ret < 0) { - PERROR("remove pidfile %s", config.pid_file_path.value); - } + ret = remove(config.pid_file_path.value); + if (ret < 0) { + PERROR("remove pidfile %s", config.pid_file_path.value); } DBG("Removing sessiond and consumerd content of directory %s", diff --git a/src/bin/lttng-sessiond/sessiond-config.c b/src/bin/lttng-sessiond/sessiond-config.c index d514aefc7..72845d0de 100644 --- a/src/bin/lttng-sessiond/sessiond-config.c +++ b/src/bin/lttng-sessiond/sessiond-config.c @@ -270,7 +270,7 @@ int sessiond_config_init(struct sessiond_config *config) ret = config_set_paths_non_root(config); } if (ret < 0) { - goto end; + goto error; } /* 32 bits consumerd path setup */ @@ -278,7 +278,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 32-bit consumer path"); - goto end; + goto error; } config_string_set(&config->consumerd32_path, str); str = NULL; @@ -287,7 +287,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 32-bit consumer error socket path"); - goto end; + goto error; } config_string_set(&config->consumerd32_err_unix_sock_path, str); str = NULL; @@ -296,7 +296,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 32-bit consumer command socket path"); - goto end; + goto error; } config_string_set(&config->consumerd32_cmd_unix_sock_path, str); str = NULL; @@ -306,7 +306,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 64-bit consumer path"); - goto end; + goto error; } config_string_set(&config->consumerd64_path, str); str = NULL; @@ -315,7 +315,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 64-bit consumer error socket path"); - goto end; + goto error; } config_string_set(&config->consumerd64_err_unix_sock_path, str); str = NULL; @@ -324,7 +324,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set 64-bit consumer command socket path"); - goto end; + goto error; } config_string_set(&config->consumerd64_cmd_unix_sock_path, str); str = NULL; @@ -334,7 +334,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set kernel consumer path"); - goto end; + goto error; } config_string_set(&config->kconsumerd_path, str); str = NULL; @@ -343,7 +343,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set kernel consumer error socket path"); - goto end; + goto error; } config_string_set(&config->kconsumerd_err_unix_sock_path, str); str = NULL; @@ -352,7 +352,7 @@ int sessiond_config_init(struct sessiond_config *config) config->rundir.value); if (ret < 0) { ERR("Failed to set kernel consumer command socket path"); - goto end; + goto error; } config_string_set(&config->kconsumerd_cmd_unix_sock_path, str); str = NULL; @@ -361,7 +361,7 @@ int sessiond_config_init(struct sessiond_config *config) DEFAULT_LTTNG_SESSIOND_PIDFILE); if (ret < 0) { ERR("Failed to set PID file path"); - goto end; + goto error; } config_string_set(&config->pid_file_path, str); str = NULL; @@ -370,7 +370,7 @@ int sessiond_config_init(struct sessiond_config *config) DEFAULT_LTTNG_SESSIOND_LOCKFILE); if (ret < 0) { ERR("Failed to set lock file path"); - goto end; + goto error; } config_string_set(&config->lock_file_path, str); str = NULL; @@ -379,7 +379,7 @@ int sessiond_config_init(struct sessiond_config *config) DEFAULT_LTTNG_SESSIOND_AGENTPORT_FILE); if (ret < 0) { ERR("Failed to set agent port file path"); - goto end; + goto error; } config_string_set(&config->agent_port_file_path, str); str = NULL; @@ -403,7 +403,9 @@ int sessiond_config_init(struct sessiond_config *config) #error "Unknown bitness" #endif ret = 0; -end: + return ret; +error: + sessiond_config_fini(config); return ret; }