summaryrefslogtreecommitdiffstats
path: root/cpukit/libmisc/shell/shell.c
diff options
context:
space:
mode:
authorJoel Sherrill <joel.sherrill@OARcorp.com>2009-11-23 21:56:50 +0000
committerJoel Sherrill <joel.sherrill@OARcorp.com>2009-11-23 21:56:50 +0000
commit13c37ad39abb4ca3529f8ce56d1b0b9fe25d6d22 (patch)
tree9fb198881ce313dcf80265d65a45a13d90e220be /cpukit/libmisc/shell/shell.c
parent2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com> (diff)
downloadrtems-13c37ad39abb4ca3529f8ce56d1b0b9fe25d6d22.tar.bz2
2009-11-23 Joel Sherrill <joel.sherrill@oarcorp.com>
* libmisc/shell/shell.c: Always duplicate the environment passed to us because we will delete it when the shell exits. If we do not duplicate it, we could end up freeing memory which was not allocated from the heap or double freeing it.
Diffstat (limited to 'cpukit/libmisc/shell/shell.c')
-rw-r--r--cpukit/libmisc/shell/shell.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/cpukit/libmisc/shell/shell.c b/cpukit/libmisc/shell/shell.c
index d270d9d92c..b87b79f01e 100644
--- a/cpukit/libmisc/shell/shell.c
+++ b/cpukit/libmisc/shell/shell.c
@@ -62,16 +62,20 @@ rtems_shell_env_t *rtems_current_shell_env = &rtems_global_shell_env;
* Initialize the shell user/process environment information
*/
rtems_shell_env_t *rtems_shell_init_env(
- rtems_shell_env_t *shell_env
+ rtems_shell_env_t *shell_env_p
)
{
- if ( !shell_env ) {
- shell_env = malloc(sizeof(rtems_shell_env_t));
- if ( !shell_env )
- return NULL;
+ rtems_shell_env_t *shell_env;
+
+ shell_env = malloc(sizeof(rtems_shell_env_t));
+ if ( !shell_env )
+ return NULL;
+ if ( !shell_env_p ) {
*shell_env = rtems_global_shell_env;
- shell_env->taskname = NULL;
+ } else {
+ *shell_env = *shell_env_p;
}
+ shell_env->taskname = NULL;
return shell_env;
}