From ca3b88c66a6be3cbb34fd81271ed39908d6bedfc Mon Sep 17 00:00:00 2001 From: Roland McGrath Date: Thu, 15 Jul 1993 00:22:55 +0000 Subject: Formerly function.c.~28~ --- function.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'function.c') diff --git a/function.c b/function.c index 5109203..c918ec9 100644 --- a/function.c +++ b/function.c @@ -324,7 +324,7 @@ expand_function (o, function, text, end) case function_shell: { - char **argv; + char **argv, **envp; char *error_prefix; int pipedes[2]; int pid; @@ -337,6 +337,9 @@ expand_function (o, function, text, end) if (argv == 0) break; + /* Construct the environment. */ + envp = target_environment ((struct file *) 0); + /* For error messages. */ if (reading_filename != 0) { @@ -357,18 +360,32 @@ expand_function (o, function, text, end) if (pid < 0) perror_with_name (error_prefix, "fork"); else if (pid == 0) - child_execute_job (0, pipedes[1], argv, environ); + child_execute_job (0, pipedes[1], argv, envp); else { - /* We are the parent. Set up and read from the pipe. */ - char *buffer = (char *) xmalloc (201); - unsigned int maxlen = 200; + /* We are the parent. */ + + char *buffer; + unsigned int maxlen; int cc; - /* Record the PID for child_handler. */ + /* Free the storage only the child needed. */ + free (argv[0]); + free ((char *) argv); + for (i = 0; envp[i] != 0; ++i) + free (envp[i]); + free ((char *) envp); + + /* Record the PID for reap_children. */ shell_function_pid = pid; shell_function_completed = 0; + + /* Set up and read from the pipe. */ + + maxlen = 200; + buffer = (char *) xmalloc (maxlen + 1); + /* Close the write side of the pipe. */ (void) close (pipedes[1]); @@ -433,8 +450,6 @@ expand_function (o, function, text, end) } } - free (argv[0]); - free ((char *) argv); free (buffer); } -- cgit v1.2.3