From 7821fecac0d0e09dd64e0ddb81e88ede44ad5d5c Mon Sep 17 00:00:00 2001 From: axel Date: Wed, 21 Sep 2005 00:51:00 +1000 Subject: [PATCH] Don't leak file descriptors when showing completion pager darcs-hash:20050920145100-ac50b-db5860389a38881177bf1fc6d377ede36700f968.gz --- ChangeLog | 5 +++++ exec.c | 57 ++++++++++++++++--------------------------------------- exec.h | 2 ++ reader.c | 2 ++ 4 files changed, 25 insertions(+), 41 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8e72ad18d..52948c081 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2005-09-20 Axel Liljencrantz + + * exec.c, reader.c (exec_read_io_buffer, run_pager): Don't leak file descriptors when showing completion pager + + 2005-09-19 Axel Liljencrantz * env_universal.c, env_universal_common.c (barrier, callback, create_message, parse_message): Add support for blocking a client until all current messages from the client and corresponding replies have been transmitted. diff --git a/exec.c b/exec.c index e15ec9b0f..08f4f83df 100644 --- a/exec.c +++ b/exec.c @@ -311,13 +311,14 @@ static int has_fd( io_data_t *d, int fd ) /** Read from descriptors until they are empty. */ -static void read_all( io_data_t *d ) +void exec_read_io_buffer( io_data_t *d ) { - -//io_data_t *d, *prev=0; - -/*for( d = io; d; d=d->next ) - {*/ + + if( close( d->pipe_fd[1] ) == -1 ) + { + debug( 1, PIPE_ERROR ); + wperror( L"close" ); + } if( d->io_mode == IO_BUFFER ) { @@ -328,7 +329,7 @@ static void read_all( io_data_t *d ) return; } - debug( 3, L"read_all: blocking read on fd %d", d->pipe_fd[0] ); + debug( 3, L"exec_read_io_buffer: blocking read on fd %d", d->pipe_fd[0] ); while(1) { @@ -337,25 +338,13 @@ static void read_all( io_data_t *d ) l=read_blocked( d->pipe_fd[0], b, 4096 ); if( l==0 ) { - -/*if( prev ) - { - prev->next = d->next; - } - else - { - j->io=d->next; - } - removed = true;*/ break; - - } else if( l<0 ) { debug( 1, L"An error occured while reading output from code block on fd %d", d->pipe_fd[0] ); - wperror( L"read_all" ); + wperror( L"exec_read_io_buffer" ); break; } else @@ -364,14 +353,9 @@ static void read_all( io_data_t *d ) } } } - -//if( !removed ) -//prev=d; -//} - -//if( current_block->io ) -//fwprintf( stderr, L"read_all ended %ls\n", j->command ); } + + io_data_t *exec_make_io_buffer() { io_data_t *buffer_redirect = malloc( sizeof( io_data_t )); @@ -412,9 +396,8 @@ void exec_free_io_buffer( io_data_t *io_buffer ) } /* - Dont free fd for writing. This should already be free'd before calling read_all on the buffer + Dont free fd for writing. This should already be free'd before calling exec_read_io_buffer on the buffer */ -// close( io_buffer->pipe_fd[1] ); b_destroy( io_buffer->out_buffer ); @@ -966,16 +949,9 @@ void exec( job_t *j ) j->io = io_remove( j->io, io_buffer ); - if( close( io_buffer->pipe_fd[1] ) == -1 ) - { - debug( 1, PIPE_ERROR ); - wperror( L"close" ); - - } + debug( 3, L"exec_read_io_buffer on block '%ls'", p->argv[0] ); - debug( 3, L"read_all on block '%ls'", p->argv[0] ); - - read_all( io_buffer ); + exec_read_io_buffer( io_buffer ); if( io_buffer->out_buffer->used != 0 ) { @@ -1233,10 +1209,9 @@ int exec_subshell( const wchar_t *cmd, prev_status = proc_get_last_status(); eval( cmd, io_buffer, SUBST ); - close( io_buffer->pipe_fd[1] ); - debug( 4, L"read_all on cmdsub '%ls'", cmd ); - read_all( io_buffer ); + debug( 4, L"exec_read_io_buffer on cmdsub '%ls'", cmd ); + exec_read_io_buffer( io_buffer ); status = proc_get_last_status(); proc_set_last_status( prev_status ); diff --git a/exec.h b/exec.h index d40de335c..f7504647b 100644 --- a/exec.h +++ b/exec.h @@ -40,4 +40,6 @@ int exec_subshell( const wchar_t *cmd, void exec_free_io_buffer( io_data_t *io_buffer ); io_data_t *exec_make_io_buffer(); +void exec_read_io_buffer( io_data_t *d ); + diff --git a/reader.c b/reader.c index 54c29f19b..7a853cf8b 100644 --- a/reader.c +++ b/reader.c @@ -1259,6 +1259,8 @@ static void run_pager( wchar_t *prefix, int is_quoted, array_list_t *comp ) eval( (wchar_t *)cmd.buff, out, TOP); term_steal(); + + exec_read_io_buffer( out ); int nil=0; b_append( out->out_buffer, &nil, 1 );