Permalink
Browse files

main: Don’t leak shell_name memory

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information...
1 parent 5af90cc commit 2686b7c634c7e060fe099dd127ddfd9a0790ad6e @andersk andersk committed with keithw Jan 26, 2013
Showing with 2 additions and 3 deletions.
  1. +2 −3 src/frontend/mosh-server.cc
@@ -245,6 +245,7 @@ int main( int argc, char *argv[] )
/* Get shell */
char *my_argv[ 2 ];
+ string shell_name;
if ( !command_argv ) {
/* get shell name */
struct passwd *pw = getpwuid( geteuid() );
@@ -260,8 +261,6 @@ int main( int argc, char *argv[] )
command_path = shell_path;
- string shell_name;
-
size_t shell_slash( shell_path.rfind('/') );
if ( shell_slash == string::npos ) {
shell_name = shell_path;
@@ -272,7 +271,7 @@ int main( int argc, char *argv[] )
/* prepend '-' to make login shell */
shell_name = '-' + shell_name;
- my_argv[ 0 ] = strdup( shell_name.c_str() );
+ my_argv[ 0 ] = const_cast<char *>( shell_name.c_str() );
my_argv[ 1 ] = NULL;
command_argv = my_argv;

0 comments on commit 2686b7c

Please sign in to comment.