diff options
author | Martin Schlemmer <azarah@gentoo.org> | 2006-07-08 23:18:59 +0000 |
---|---|---|
committer | Martin Schlemmer <azarah@gentoo.org> | 2006-07-08 23:18:59 +0000 |
commit | 471dd994a807cd783aa80403358231a7f94ce1b2 (patch) | |
tree | 29a2d0e307fa4d3fbd5c157fc0738441550dbc09 /src | |
parent | Rather link libsandbox against librcutil's libtool objects (.lo), (diff) | |
download | sandbox-471dd994a807cd783aa80403358231a7f94ce1b2.tar.gz sandbox-471dd994a807cd783aa80403358231a7f94ce1b2.tar.bz2 sandbox-471dd994a807cd783aa80403358231a7f94ce1b2.zip |
Free child environ we allocated earlier, as at execve() duplicates
this, so no need to keep it around and waiste more memory.
Signed-off-by: Martin Schlemmer <azarah@gentoo.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/sandbox.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/sandbox.c b/src/sandbox.c index 057ca7a..4b3e87f 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -527,7 +527,7 @@ error: return NULL; } -int spawn_shell(char *argv_bash[], char *env[], int debug) +int spawn_shell(char *argv_bash[], char **env, int debug) { int status = 0; int ret = 0; @@ -543,6 +543,11 @@ int spawn_shell(char *argv_bash[], char *env[], int debug) fprintf(stderr, "Process failed to spawn!\n"); return 0; } + + /* execve() creates a copy of this, so no need to use more memory than + * absolutely needed. */ + str_list_free(env); + ret = waitpid(child_pid, &status, 0); if ((-1 == ret) || (status > 0)) { if (debug) @@ -640,7 +645,8 @@ int main(int argc, char **argv) } } - /* Setup the child environment stuff */ + /* Setup the child environment stuff. + * XXX: We free this in spawn_shell(). */ sandbox_environ = sandbox_setup_environ(&sandbox_info, print_debug); if (NULL == sandbox_environ) goto oom_error; @@ -668,9 +674,8 @@ int main(int argc, char **argv) if (!spawn_shell(argv_bash, sandbox_environ, print_debug)) success = 0; - /* Free bash and envp stuff */ + /* Free bash argv stuff */ str_list_free(argv_bash); - str_list_free(sandbox_environ); if (print_debug) printf("Cleaning up sandbox process\n"); |