Fix: leak of sessiond configuration on launch of run-as worker
[lttng-tools.git] / src / bin / lttng-sessiond / main.c
index 7f66a7271222d16b11dbb501ddf7dd5c0e291fb2..24855b9767632bc1584316b0b0c80362d870c2e5 100644 (file)
@@ -1336,6 +1336,26 @@ static void destroy_all_sessions_and_wait(void)
        DBG("Destruction of all sessions completed");
 }
 
+static int run_as_worker_post_fork_cleanup(void *data)
+{
+       struct sessiond_config *sessiond_config = data;
+
+       sessiond_config_fini(sessiond_config);
+       return 0;
+}
+
+static int launch_run_as_worker(const char *procname)
+{
+       /*
+        * Clean-up before forking the run-as worker. Any dynamically
+        * allocated memory of which the worker is not aware will
+        * be leaked as the process forks a run-as worker (and performs
+        * no exec*()). The same would apply to any opened fd.
+        */
+       return run_as_create_worker(procname, run_as_worker_post_fork_cleanup,
+                       &config);
+}
+
 /*
  * main
  */
@@ -1469,7 +1489,7 @@ int main(int argc, char **argv)
                }
        }
 
-       if (run_as_create_worker(argv[0]) < 0) {
+       if (launch_run_as_worker(argv[0]) < 0) {
                goto exit_create_run_as_worker_cleanup;
        }
 
@@ -1626,12 +1646,6 @@ int main(int argc, char **argv)
                goto stop_threads;
        }
 
-       /* Set credentials to socket */
-       if (is_root && set_permissions(config.rundir.value)) {
-               retval = -1;
-               goto stop_threads;
-       }
-
        /* Get parent pid if -S, --sig-parent is specified. */
        if (config.sig_parent) {
                ppid = getppid();
@@ -1741,6 +1755,12 @@ int main(int argc, char **argv)
                goto stop_threads;
        }
 
+       /* Set credentials of the client socket and rundir */
+       if (is_root && set_permissions(config.rundir.value)) {
+               retval = -1;
+               goto stop_threads;
+       }
+
        if (!launch_ust_dispatch_thread(&ust_cmd_queue, apps_cmd_pipe[1],
                        apps_cmd_notify_pipe[1])) {
                retval = -1;
This page took 0.024046 seconds and 4 git commands to generate.