chiark / gitweb /
execute,util: fix two small memory leaks
[elogind.git] / src / execute.c
index 48e55ea4c2f60c08891ff64e63477b91deb0c048..1e8dfaf7700fa7f62f712105b570e73062873fbb 100644 (file)
@@ -1252,7 +1252,7 @@ int exec_spawn(ExecCommand *command,
                                 }
                 }
 
-                if (!(our_env = new0(char*, 6))) {
+                if (!(our_env = new0(char*, 7))) {
                         r = EXIT_MEMORY;
                         goto fail;
                 }
@@ -1277,7 +1277,15 @@ int exec_spawn(ExecCommand *command,
                                 goto fail;
                         }
 
-                assert(n_env <= 6);
+                if (is_terminal_input(context->std_input) ||
+                    context->std_output == EXEC_OUTPUT_TTY ||
+                    context->std_error == EXEC_OUTPUT_TTY)
+                        if (!(our_env[n_env++] = strdup(default_term_for_tty(tty_path(context))))) {
+                                r = EXIT_MEMORY;
+                                goto fail;
+                        }
+
+                assert(n_env <= 7);
 
                 if (!(final_env = strv_env_merge(
                                       4,
@@ -1295,6 +1303,8 @@ int exec_spawn(ExecCommand *command,
                         goto fail;
                 }
 
+                final_env = strv_env_clean(final_env);
+
                 execve(command->path, final_argv, final_env);
                 r = EXIT_EXEC;
 
@@ -1396,6 +1406,9 @@ void exec_context_done(ExecContext *c) {
 
         if (c->cpuset)
                 CPU_FREE(c->cpuset);
+
+        free(c->utmp_id);
+        c->utmp_id = NULL;
 }
 
 void exec_command_done(ExecCommand *c) {