Squash a bunch of leaks

This commit is contained in:
ridiculousfish 2012-02-21 19:33:11 -08:00
parent e074ad4807
commit 5fe7c065dc
6 changed files with 31 additions and 35 deletions

View file

@ -292,7 +292,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
int authoritative = -1;
int flags = COMPLETE_AUTO_SPACE;
string_buffer_t short_opt;
wcstring short_opt;
wcstring_list_t gnu_opt, old_opt;
const wchar_t *comp=L"", *desc=L"", *condition=L"";
@ -303,8 +303,6 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
static int recursion_level=0;
sb_init( &short_opt );
argc = builtin_count_args( argv );
woptind=0;
@ -455,7 +453,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
break;
case 's':
sb_append( &short_opt, woptarg );
short_opt.append(woptarg);
break;
case 'l':
@ -604,7 +602,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
{
builtin_complete_remove( cmd,
path,
(wchar_t *)short_opt.buff,
short_opt.c_str(),
gnu_opt,
old_opt );
}
@ -612,7 +610,7 @@ static int builtin_complete( parser_t &parser, wchar_t **argv )
{
builtin_complete_add( cmd,
path,
(wchar_t *)short_opt.buff,
short_opt.c_str(),
gnu_opt,
old_opt,
result_mode,

View file

@ -26,6 +26,7 @@
#include <vector>
#include <deque>
#include <algorithm>
#include <memory>
#ifdef HAVE_SIGINFO_H
#include <siginfo.h>
@ -286,7 +287,7 @@ static int handle_child_io( io_data_t *io )
case IO_FILE:
{
if( (tmp=wopen( io->param1.filename,
if( (tmp=wopen( io->filename,
io->param2.flags, OPEN_MASK ) )==-1 )
{
if( ( io->param2.flags & O_EXCL ) &&
@ -294,13 +295,13 @@ static int handle_child_io( io_data_t *io )
{
debug( 1,
NOCLOB_ERROR,
io->param1.filename );
io->filename.c_str() );
}
else
{
debug( 1,
FILE_ERROR,
io->param1.filename );
io->filename.c_str() );
wperror( L"open" );
}
@ -659,7 +660,7 @@ static void io_untransmogrify( io_data_t * in, io_data_t *out )
exec_close( out->param1.old_fd );
break;
}
free(out);
delete out;
}
@ -674,14 +675,10 @@ static void io_untransmogrify( io_data_t * in, io_data_t *out )
*/
static io_data_t *io_transmogrify( io_data_t * in )
{
io_data_t *out;
if( !in )
return 0;
out = (io_data_t *)malloc( sizeof( io_data_t ) );
if( !out )
DIE_MEM();
std::auto_ptr<io_data_t> out(new io_data_t());
out->fd = in->fd;
out->io_mode = IO_FD;
@ -698,7 +695,7 @@ static io_data_t *io_transmogrify( io_data_t * in )
case IO_BUFFER:
case IO_PIPE:
{
memcpy( out, in, sizeof(io_data_t));
*out = *in;
break;
}
@ -709,15 +706,14 @@ static io_data_t *io_transmogrify( io_data_t * in )
{
int fd;
if( (fd=wopen( in->param1.filename, in->param2.flags, OPEN_MASK ) )==-1 )
if( (fd=wopen( in->filename, in->param2.flags, OPEN_MASK ) )==-1 )
{
debug( 1,
FILE_ERROR,
in->param1.filename );
in->filename.c_str() );
wperror( L"open" );
free( out );
return 0;
return NULL;
}
out->param1.old_fd = fd;
@ -730,12 +726,12 @@ static io_data_t *io_transmogrify( io_data_t * in )
out->next = io_transmogrify( in->next );
if( !out->next )
{
io_untransmogrify( in, out );
return 0;
io_untransmogrify( in, out.release() );
return NULL;
}
}
return out;
return out.release();
}
/**
@ -1246,13 +1242,13 @@ void exec( parser_t &parser, job_t *j )
case IO_FILE:
{
builtin_stdin=wopen( in->param1.filename,
builtin_stdin=wopen( in->filename,
in->param2.flags, OPEN_MASK );
if( builtin_stdin == -1 )
{
debug( 1,
FILE_ERROR,
in->param1.filename );
in->filename.c_str() );
wperror( L"open" );
}
else
@ -1530,7 +1526,7 @@ void exec( parser_t &parser, job_t *j )
for( io = j->io; io; io=io->next )
{
if( io->io_mode == IO_FILE && wcscmp(io->param1.filename, L"/dev/null" ))
if( io->io_mode == IO_FILE && io->filename != L"/dev/null")
{
skip_fork = 0;
}

View file

@ -765,6 +765,7 @@ void history_t::add_with_file_detection(const wcstring &str)
}
}
}
tok_destroy(&tokenizer);
if (! potential_paths.empty()) {
/* We have some paths. Make a context. */

2
io.cpp
View file

@ -100,7 +100,7 @@ void io_buffer_read( io_data_t *d )
io_data_t *io_buffer_create( int is_input )
{
io_data_t *buffer_redirect = (io_data_t *)malloc( sizeof( io_data_t ));
io_data_t *buffer_redirect = new io_data_t();
buffer_redirect->io_mode=IO_BUFFER;
buffer_redirect->next=0;

9
io.h
View file

@ -24,12 +24,13 @@ struct io_data_t
{
/** Fds for IO_PIPE and for IO_BUFFER */
int pipe_fd[2];
/** Filename IO_FILE */
wchar_t *filename;
/** fd to redirect specified fd to, for IO_FD*/
int old_fd;
} param1
;
} param1;
/** Filename IO_FILE */
wcstring filename;
/**
Second type-specific paramter for redirection
*/

View file

@ -1486,25 +1486,25 @@ void parser_t::parse_job_argument_list( process_t *p,
case TOK_REDIRECT_APPEND:
new_io->io_mode = IO_FILE;
new_io->param2.flags = O_CREAT | O_APPEND | O_WRONLY;
new_io->param1.filename = wcsdup(target.c_str()); // PCA LEAKS!
new_io->filename = target;
break;
case TOK_REDIRECT_OUT:
new_io->io_mode = IO_FILE;
new_io->param2.flags = O_CREAT | O_WRONLY | O_TRUNC;
new_io->param1.filename = wcsdup(target.c_str()); // PCA LEAKS!
new_io->filename = target;
break;
case TOK_REDIRECT_NOCLOB:
new_io->io_mode = IO_FILE;
new_io->param2.flags = O_CREAT | O_EXCL | O_WRONLY;
new_io->param1.filename = wcsdup(target.c_str()); // PCA LEAKS!
new_io->filename = target;
break;
case TOK_REDIRECT_IN:
new_io->io_mode = IO_FILE;
new_io->param2.flags = O_RDONLY;
new_io->param1.filename = wcsdup(target.c_str()); // PCA LEAKS!
new_io->filename = target;
break;
case TOK_REDIRECT_FD: