From ec43090c16d72bd481bff016d483e8f231abccef Mon Sep 17 00:00:00 2001 From: axel Date: Sun, 12 Nov 2006 22:16:13 +1000 Subject: [PATCH] Fix file descriptor leakage from completion pager darcs-hash:20061112121613-ac50b-209d42c06401faf675ff123236823dcaa651d6f7.gz --- exec.c | 2 +- io.c | 16 ++++++++++++---- io.h | 11 +---------- reader.c | 3 +-- 4 files changed, 15 insertions(+), 17 deletions(-) diff --git a/exec.c b/exec.c index dd8ee76bc..2eecaf33a 100644 --- a/exec.c +++ b/exec.c @@ -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 diff --git a/io.c b/io.c index e5afa06b4..967c785f0 100644 --- a/io.c +++ b/io.c @@ -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 ) ) @@ -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; @@ -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] ); /* diff --git a/io.h b/io.h index 38b87e3d9..26b2ddcde 100644 --- a/io.h +++ b/io.h @@ -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; diff --git a/reader.c b/reader.c index 77fa02336..77ac5297a 100644 --- a/reader.c +++ b/reader.c @@ -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 @@ -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); - } /**