main: Don’t leak shell_name memory
Signed-off-by: Anders Kaseorg <andersk@mit.edu>
This commit is contained in:
committed by
Keith Winstein
parent
5af90cc1ac
commit
2686b7c634
@@ -245,6 +245,7 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
/* Get shell */
|
/* Get shell */
|
||||||
char *my_argv[ 2 ];
|
char *my_argv[ 2 ];
|
||||||
|
string shell_name;
|
||||||
if ( !command_argv ) {
|
if ( !command_argv ) {
|
||||||
/* get shell name */
|
/* get shell name */
|
||||||
struct passwd *pw = getpwuid( geteuid() );
|
struct passwd *pw = getpwuid( geteuid() );
|
||||||
@@ -260,8 +261,6 @@ int main( int argc, char *argv[] )
|
|||||||
|
|
||||||
command_path = shell_path;
|
command_path = shell_path;
|
||||||
|
|
||||||
string shell_name;
|
|
||||||
|
|
||||||
size_t shell_slash( shell_path.rfind('/') );
|
size_t shell_slash( shell_path.rfind('/') );
|
||||||
if ( shell_slash == string::npos ) {
|
if ( shell_slash == string::npos ) {
|
||||||
shell_name = shell_path;
|
shell_name = shell_path;
|
||||||
@@ -272,7 +271,7 @@ int main( int argc, char *argv[] )
|
|||||||
/* prepend '-' to make login shell */
|
/* prepend '-' to make login shell */
|
||||||
shell_name = '-' + shell_name;
|
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;
|
my_argv[ 1 ] = NULL;
|
||||||
command_argv = my_argv;
|
command_argv = my_argv;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user