From 5e842e0783a17dc68ec8976325747308a9090516 Mon Sep 17 00:00:00 2001 From: Eamonn Webster Date: Mon, 21 Oct 2013 12:45:40 +0100 Subject: [PATCH] always close the old stream --- ChangeLog | 6 ++++++ ext/readline/readline.c | 14 ++------------ test/readline/test_readline.rb | 4 ++++ 3 files changed, 12 insertions(+), 12 deletions(-) diff --git a/ChangeLog b/ChangeLog index 53e320b..9b3a28a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Oct 21 21:19:34 2013 Eamonn Webster + + * ext/readline/readline.c: Always close the file as we dup'ed the descriptor + + * test/readline/test_readline.rb: Assign a 10,000 times shouldn't run out of handles + Fri Oct 18 15:23:34 2013 Koichi Sasada * gc.c: change terminology of heap. diff --git a/ext/readline/readline.c b/ext/readline/readline.c index 0f76d1a..2a0c753 100644 --- a/ext/readline/readline.c +++ b/ext/readline/readline.c @@ -456,14 +456,9 @@ readline_readline(int argc, VALUE *argv, VALUE self) static void clear_rl_instream(void) { - rb_io_t *ifp; if (rl_instream) { if (readline_instream) { - rb_io_check_initialized(ifp = RFILE(rb_io_taint_check(readline_instream))->fptr); - if (ifp->fd < 0 || fileno(rl_instream) == ifp->fd) { - fclose(rl_instream); - rl_instream = NULL; - } + fclose(rl_instream); } readline_instream = Qfalse; rl_instream = NULL; @@ -510,14 +505,9 @@ readline_s_set_input(VALUE self, VALUE input) static void clear_rl_outstream(void) { - rb_io_t *ofp; if (rl_outstream) { if (readline_outstream) { - rb_io_check_initialized(ofp = RFILE(rb_io_taint_check(readline_outstream))->fptr); - if (ofp->fd < 0 || fileno(rl_outstream) == ofp->fd) { - fclose(rl_outstream); - rl_outstream = NULL; - } + fclose(rl_outstream); } readline_outstream = Qfalse; rl_outstream = NULL; diff --git a/test/readline/test_readline.rb b/test/readline/test_readline.rb index 57cf223..6f940a2 100644 --- a/test/readline/test_readline.rb +++ b/test/readline/test_readline.rb @@ -295,6 +295,10 @@ class TestReadline < Test::Unit::TestCase end end + def test_close_streams + assert_equal(10000, 10000.times{ Readline.input = STDIN }) + end + def test_closed_outstream bug5803 = '[ruby-dev:45043]' IO.pipe do |r, w| -- 1.8.4