Do not attempt to free() the application's environment, which is was

not dynamically allocated.  Instead, use a private variable to store
the environment array, which is used when we exec applications.
This commit is contained in:
Eric Andersen 2005-04-27 11:44:11 +00:00
parent fef32b570b
commit 70a5a1abde

View File

@ -150,9 +150,7 @@ struct interfaces_file_t
static char no_act = 0; static char no_act = 0;
static char verbose = 0; static char verbose = 0;
#ifndef __USE_GNU static char **__myenviron = NULL;
static char **environ = NULL;
#endif
#ifdef CONFIG_FEATURE_IFUPDOWN_IP #ifdef CONFIG_FEATURE_IFUPDOWN_IP
@ -963,16 +961,16 @@ static void set_environ(struct interface_defn_t *iface, char *mode)
const int n_env_entries = iface->n_options + 5; const int n_env_entries = iface->n_options + 5;
char **ppch; char **ppch;
if (environ != NULL) { if (__myenviron != NULL) {
for (ppch = environ; *ppch; ppch++) { for (ppch = __myenviron; *ppch; ppch++) {
free(*ppch); free(*ppch);
*ppch = NULL; *ppch = NULL;
} }
free(environ); free(__myenviron);
environ = NULL; __myenviron = NULL;
} }
environ = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ )); __myenviron = xmalloc(sizeof(char *) * (n_env_entries + 1 /* for final NULL */ ));
environend = environ; environend = __myenviron;
*environend = NULL; *environend = NULL;
for (i = 0; i < iface->n_options; i++) { for (i = 0; i < iface->n_options; i++) {
@ -1012,7 +1010,7 @@ static int doit(char *str)
case -1: /* failure */ case -1: /* failure */
return 0; return 0;
case 0: /* child */ case 0: /* child */
execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, environ); execle(DEFAULT_SHELL, DEFAULT_SHELL, "-c", str, NULL, __myenviron);
exit(127); exit(127);
} }
waitpid(child, &status, 0); waitpid(child, &status, 0);