From: Yu Watanabe Date: Thu, 8 Nov 2018 05:08:10 +0000 (+0900) Subject: core: introduce exec_params_clear() X-Git-Tag: v240~386 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=b9c04eafb8f8b905919c5fe1feba6e0b04f46726;p=thirdparty%2Fsystemd.git core: introduce exec_params_clear() Follow-up for 1ad6e8b302e87b6891a2bfc35ad397b0afe3d940. Fixes #10677. --- diff --git a/src/core/execute.c b/src/core/execute.c index 33aa1093a31..435d94a86d6 100644 --- a/src/core/execute.c +++ b/src/core/execute.c @@ -5112,6 +5112,13 @@ void exec_runtime_vacuum(Manager *m) { } } +void exec_params_clear(ExecParameters *p) { + if (!p) + return; + + strv_free(p->environment); +} + static const char* const exec_input_table[_EXEC_INPUT_MAX] = { [EXEC_INPUT_NULL] = "null", [EXEC_INPUT_TTY] = "tty", diff --git a/src/core/execute.h b/src/core/execute.h index fa08746260a..11a9b45dccf 100644 --- a/src/core/execute.h +++ b/src/core/execute.h @@ -383,6 +383,8 @@ int exec_runtime_deserialize_compat(Unit *u, const char *key, const char *value, void exec_runtime_deserialize_one(Manager *m, const char *value, FDSet *fds); void exec_runtime_vacuum(Manager *m); +void exec_params_clear(ExecParameters *p); + const char* exec_output_to_string(ExecOutput i) _const_; ExecOutput exec_output_from_string(const char *s) _pure_; diff --git a/src/core/mount.c b/src/core/mount.c index 14f1fa9e50f..5e1ef1e6ace 100644 --- a/src/core/mount.c +++ b/src/core/mount.c @@ -747,7 +747,7 @@ static void mount_dump(Unit *u, FILE *f, const char *prefix) { static int mount_spawn(Mount *m, ExecCommand *c, pid_t *_pid) { - ExecParameters exec_params = { + _cleanup_(exec_params_clear) ExecParameters exec_params = { .flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN, .stdin_fd = -1, .stdout_fd = -1, diff --git a/src/core/service.c b/src/core/service.c index 8fc8d1ff949..50ceda7ac60 100644 --- a/src/core/service.c +++ b/src/core/service.c @@ -1399,7 +1399,7 @@ static int service_spawn( ExecFlags flags, pid_t *_pid) { - ExecParameters exec_params = { + _cleanup_(exec_params_clear) ExecParameters exec_params = { .flags = flags, .stdin_fd = -1, .stdout_fd = -1, @@ -1538,7 +1538,7 @@ static int service_spawn( SET_FLAG(exec_params.flags, EXEC_NSS_BYPASS_BUS, MANAGER_IS_SYSTEM(UNIT(s)->manager) && unit_has_name(UNIT(s), SPECIAL_DBUS_SERVICE)); - exec_params.environment = final_env; + strv_free_and_replace(exec_params.environment, final_env); exec_params.fds = fds; exec_params.fd_names = fd_names; exec_params.n_socket_fds = n_socket_fds; diff --git a/src/core/socket.c b/src/core/socket.c index ad8b9b6a416..407ad1352c8 100644 --- a/src/core/socket.c +++ b/src/core/socket.c @@ -1860,7 +1860,7 @@ static int socket_coldplug(Unit *u) { static int socket_spawn(Socket *s, ExecCommand *c, pid_t *_pid) { - ExecParameters exec_params = { + _cleanup_(exec_params_clear) ExecParameters exec_params = { .flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN, .stdin_fd = -1, .stdout_fd = -1, diff --git a/src/core/swap.c b/src/core/swap.c index 429b2b1062a..ff1412879f3 100644 --- a/src/core/swap.c +++ b/src/core/swap.c @@ -596,7 +596,7 @@ static void swap_dump(Unit *u, FILE *f, const char *prefix) { static int swap_spawn(Swap *s, ExecCommand *c, pid_t *_pid) { - ExecParameters exec_params = { + _cleanup_(exec_params_clear) ExecParameters exec_params = { .flags = EXEC_APPLY_SANDBOXING|EXEC_APPLY_CHROOT|EXEC_APPLY_TTY_STDIN, .stdin_fd = -1, .stdout_fd = -1,