[前][次][番号順一覧][スレッド一覧]

ruby-changes:45130

From: nobu <ko1@a...>
Date: Tue, 27 Dec 2016 16:18:31 +0900 (JST)
Subject: [ruby-changes:45130] nobu:r57203 (trunk): io.c: ARGF fd leak

nobu	2016-12-27 16:18:27 +0900 (Tue, 27 Dec 2016)

  New Revision: 57203

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57203

  Log:
    io.c: ARGF fd leak
    
    * io.c (argf_next_argv): fix leak of fd after breaking in #each
      method.

  Modified files:
    trunk/io.c
    trunk/test/ruby/test_argf.rb
Index: test/ruby/test_argf.rb
===================================================================
--- test/ruby/test_argf.rb	(revision 57202)
+++ test/ruby/test_argf.rb	(revision 57203)
@@ -137,7 +137,7 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L137
     INPUT
   end
 
-  def test_new_lineno
+  def test_new_lineno_each
     f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
     result = []
     f.each {|line| result << [f.lineno, line]; break if result.size == 3}
@@ -146,10 +146,16 @@ class TestArgf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_argf.rb#L146
 
     f.rewind
     assert_equal(2, f.lineno)
+  ensure
+    f.close
+  end
 
+  def test_new_lineno_each_char
     f = ARGF.class.new(@t1.path, @t2.path, @t3.path)
     f.each_char.to_a
     assert_equal(0, f.lineno)
+  ensure
+    f.close
   end
 
   def test_inplace
Index: io.c
===================================================================
--- io.c	(revision 57202)
+++ io.c	(revision 57203)
@@ -8023,6 +8023,7 @@ argf_next_argv(VALUE argf) https://github.com/ruby/ruby/blob/trunk/io.c#L8023
     }
 
     if (ARGF.next_p == 1) {
+	if (ARGF.init_p == 1) argf_close(argf);
       retry:
 	if (RARRAY_LEN(ARGF.argv) > 0) {
 	    VALUE filename = rb_ary_shift(ARGF.argv);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]