Fix: clean-up sessiond condig structure on initialization error
authorJérémie Galarneau <jeremie.galarneau@efficios.com>
Mon, 20 Aug 2018 19:50:48 +0000 (15:50 -0400)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 7 Sep 2018 16:14:56 +0000 (12:14 -0400)
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 <jeremie.galarneau@efficios.com>
src/bin/lttng-sessiond/main.c
src/bin/lttng-sessiond/sessiond-config.c

index 88877c700437d54713020f4dc06c66f543fe4d67..f7b3c7c84d1add69c1114e89f81ac4911490b33d 100644 (file)
@@ -547,15 +547,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",
index d514aefc75e8ba85639cf0f80a3e9f5ec54b51fd..72845d0de3923786ff75f2012295c1e79f0219d9 100644 (file)
@@ -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;
 }
 
This page took 0.032116 seconds and 5 git commands to generate.