Change parser_t::parse_job's args array to be a local, rather than just leak it, which no longer seems to crash

This commit is contained in:
ridiculousfish
2012-01-31 16:50:03 -08:00
parent af2d348543
commit 0c9e398bef
7 changed files with 43 additions and 41 deletions

View File

@@ -1616,7 +1616,7 @@ int parser_t::parse_job( process_t *p,
tokenizer *tok )
{
// array_list_t *args = al_halloc( j ); // The list that will become the argc array for the program
std::vector<completion_t> *args = new std::vector<completion_t>();
std::vector<completion_t> args;
int use_function = 1; // May functions be considered when checking what action this command represents
int use_builtin = 1; // May builtins be considered when checking what action this command represents
int use_command = 1; // May commands be considered when checking what action this command represents
@@ -1627,7 +1627,7 @@ int parser_t::parse_job( process_t *p,
current_tokenizer_pos = tok_get_pos( tok );
while( args->size() == 0 )
while( args.size() == 0 )
{
wchar_t *nxt=0;
int consumed = 0; // Set to one if the command requires a second command, like e.g. while does
@@ -1876,7 +1876,7 @@ int parser_t::parse_job( process_t *p,
}
completion_t data_to_push;
data_to_push.completion = nxt;
args->push_back( data_to_push );
args.push_back( data_to_push );
}
if( error_code == 0 )
@@ -1884,10 +1884,10 @@ int parser_t::parse_job( process_t *p,
if( !p->type )
{
if( use_builtin &&
builtin_exists(args->at(0).completion.c_str()))
builtin_exists(args.at(0).completion.c_str()))
{
p->type = INTERNAL_BUILTIN;
is_new_block |= parser_keywords_is_block( args->at( 0 ).completion );
is_new_block |= parser_keywords_is_block( args.at( 0 ).completion );
}
}
@@ -1904,7 +1904,7 @@ int parser_t::parse_job( process_t *p,
else
{
int err;
p->actual_cmd = path_get_path( args->at(0).completion.c_str() );
p->actual_cmd = path_get_path( args.at(0).completion.c_str() );
err = errno;
/*
@@ -1918,24 +1918,18 @@ int parser_t::parse_job( process_t *p,
directory, in which case, we use 'cd' as the
implicit command.
*/
wchar_t *pp =
path_get_cdpath( j, args->at(0).completion.c_str() );
if( pp )
if(path_can_get_cdpath(args.at(0).completion))
{
wchar_t *tmp;
tmp = (wchar_t *)wcsdup(args->at( 0 ).completion.c_str());
wcstring tmp = args.at(0).completion;
// al_truncate( args, 0 );
args->clear();
args.clear();
// al_push( args, halloc_wcsdup( j, L"cd" ) );
completion_t comp;
comp.completion = L"cd";
args->push_back(comp);
args.push_back(comp);
completion_t comp2;
comp2.completion = tmp;
args->push_back( comp2 );
// free(tmp);
args.push_back( comp2 );
/*
If we have defined a wrapper around cd, use it,
otherwise use the cd builtin
@@ -1948,7 +1942,7 @@ int parser_t::parse_job( process_t *p,
else
{
int tmp;
wchar_t *cmd = (wchar_t *)args->at( 0 ).completion.c_str();
const wchar_t *cmd = args.at( 0 ).completion.c_str();
/*
We couldn't find the specified command.
@@ -2029,7 +2023,7 @@ int parser_t::parse_job( process_t *p,
current_tokenizer_pos=tmp;
job_set_flag( j, JOB_SKIP, 1 );
event_fire_generic(L"fish_command_not_found", (wchar_t *)( args->at( 0 ).completion.c_str() ) );
event_fire_generic(L"fish_command_not_found", (wchar_t *)( args.at( 0 ).completion.c_str() ) );
proc_set_last_status( err==ENOENT?STATUS_UNKNOWN_COMMAND:STATUS_NOT_EXECUTABLE );
}
}
@@ -2041,7 +2035,7 @@ int parser_t::parse_job( process_t *p,
error( SYNTAX_ERROR,
tok_get_pos( tok ),
UNKNOWN_BUILTIN_ERR_MSG,
args->back().completion.c_str() );
args.back().completion.c_str() );
}
}
@@ -2118,7 +2112,7 @@ int parser_t::parse_job( process_t *p,
p->type = INTERNAL_BLOCK;
completion_t data_to_push;
data_to_push.completion = sub_block;
args->at( 0 ) = data_to_push;
args.at( 0 ) = data_to_push;
tok_set_pos( tok,
end_pos );
@@ -2137,14 +2131,14 @@ int parser_t::parse_job( process_t *p,
if( !error_code )
{
if( p->type == INTERNAL_BUILTIN && parser_keywords_skip_arguments( (wchar_t *)args->at( 0 ).completion.c_str() ) )
if( p->type == INTERNAL_BUILTIN && parser_keywords_skip_arguments(args.at(0).completion))
{
if( !p->get_argv() )
p->set_argv(completions_to_char_arr( *args ));
p->set_argv(completions_to_char_arr(args));
}
else
{
parse_job_argument_list( p, j, tok, *args );
parse_job_argument_list(p, j, tok, args);
}
}