mirror of
https://github.com/fish-shell/fish-shell
synced 2025-01-14 05:53:59 +00:00
Minor tweaks to expand_Variables, fixes rare memory leak
darcs-hash:20060207114857-ac50b-9b2ecf31106678ec35d888066162bf14605c6003.gz
This commit is contained in:
parent
c4dfdfa849
commit
ddff3561e3
1 changed files with 68 additions and 56 deletions
20
expand.c
20
expand.c
|
@ -713,6 +713,17 @@ static int expand_pid( wchar_t *in,
|
|||
|
||||
/**
|
||||
Expand all environment variables in the string *ptr.
|
||||
|
||||
This function is slow, fragile and complicated. There are lots of
|
||||
little corner cases, like $$foo should do a double expansion,
|
||||
$foo$bar should not double expand bar, etc. Also, it's easy to
|
||||
accidentally leak memory on array out of bounds errors an various
|
||||
other situations. All in all, this function should be rewritten,
|
||||
split out into multiple logical units and carefully tested. After
|
||||
that, it can probably be optimized to do fewer memory allocations,
|
||||
fewer string scans and overall just less work. But until that
|
||||
happens, don't edit it unless you know exactly what you are doing,
|
||||
and do proper testing afterwards.
|
||||
*/
|
||||
static int expand_variables( wchar_t *in, array_list_t *out )
|
||||
{
|
||||
|
@ -885,6 +896,9 @@ static int expand_variables( wchar_t *in, array_list_t *out )
|
|||
free( var_val );
|
||||
}
|
||||
|
||||
if( is_ok )
|
||||
{
|
||||
|
||||
if( is_single )
|
||||
{
|
||||
string_buffer_t res;
|
||||
|
@ -908,10 +922,7 @@ static int expand_variables( wchar_t *in, array_list_t *out )
|
|||
free( next );
|
||||
}
|
||||
sb_append( &res, &in[stop_pos] );
|
||||
is_ok &= expand_variables( wcsdup((wchar_t *)res.buff), out );
|
||||
|
||||
sb_destroy( &res );
|
||||
|
||||
is_ok &= expand_variables( (wchar_t *)res.buff, out );
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -951,6 +962,7 @@ static int expand_variables( wchar_t *in, array_list_t *out )
|
|||
free( next );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
al_destroy( &l );
|
||||
al_destroy( &idx );
|
||||
|
|
Loading…
Reference in a new issue