Skip to content

Commit

Permalink
Fix file descriptor leakage from completion pager
Browse files Browse the repository at this point in the history
darcs-hash:20061112121613-ac50b-209d42c06401faf675ff123236823dcaa651d6f7.gz
  • Loading branch information
liljencrantz committed Nov 12, 2006
1 parent 80759ee commit ec43090
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 17 deletions.
2 changes: 1 addition & 1 deletion exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -704,7 +704,7 @@ void exec( job_t *j )

if( input_redirect &&
(input_redirect->io_mode == IO_BUFFER) &&
input_redirect->param3.is_input )
input_redirect->is_input )
{
/*
Input redirection - create a new gobetween process to take
Expand Down
16 changes: 12 additions & 4 deletions io.c
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,8 @@ Utilities for io redirection.

void io_buffer_read( io_data_t *d )
{

exec_close(d->param1.pipe_fd[1] );

if( d->io_mode == IO_BUFFER )
{
/* if( fcntl( d->param1.pipe_fd[0], F_SETFL, 0 ) )
Expand Down Expand Up @@ -108,7 +107,7 @@ io_data_t *io_buffer_create( int is_input )
buffer_redirect->io_mode=IO_BUFFER;
buffer_redirect->next=0;
buffer_redirect->param2.out_buffer= malloc( sizeof(buffer_t));
buffer_redirect->param3.is_input = is_input;
buffer_redirect->is_input = is_input;
b_init( buffer_redirect->param2.out_buffer );
buffer_redirect->fd=is_input?0:1;

Expand All @@ -135,7 +134,16 @@ io_data_t *io_buffer_create( int is_input )

void io_buffer_destroy( io_data_t *io_buffer )
{


/**
If this is an input buffer, then io_read_buffer will not have
been called, and we need to close the output fd as well.
*/
if( io_buffer->is_input )
{
exec_close(io_buffer->param1.pipe_fd[1] );
}

exec_close( io_buffer->param1.pipe_fd[0] );

/*
Expand Down
11 changes: 1 addition & 10 deletions io.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,7 @@ typedef struct io_data
} param2
;

union
{
/**
This will be non-zero if this is a buffer of input, not
output
*/
int is_input;
}
param3;

int is_input;

/** Pointer to the next IO redirection */
struct io_data *next;
Expand Down
3 changes: 1 addition & 2 deletions reader.c
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp )
string_buffer_t msg;
wchar_t * prefix_esc;
char *foo;

if( !prefix || (wcslen(prefix)==0))
prefix_esc = wcsdup(L"\"\"");
else
Expand Down Expand Up @@ -1026,7 +1026,6 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp )

io_buffer_destroy( out);
io_buffer_destroy( in);

}

/**
Expand Down

0 comments on commit ec43090

Please sign in to comment.