ruby-changes:34143
From: akr <ko1@a...>
Date: Thu, 29 May 2014 19:45:04 +0900 (JST)
Subject: [ruby-changes:34143] akr:r46224 (trunk): * lib/csv.rb (CSV.open): Close the opened file when an exception occur.
akr 2014-05-29 19:44:59 +0900 (Thu, 29 May 2014) New Revision: 46224 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?revision=46224&view=revision Log: * lib/csv.rb (CSV.open): Close the opened file when an exception occur. Modified files: trunk/ChangeLog trunk/lib/csv.rb trunk/test/csv/test_features.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46223) +++ ChangeLog (revision 46224) @@ -1,7 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Thu May 29 19:42:49 2014 Tanaka Akira <akr@f...> + + * lib/csv.rb (CSV.open): Close the opened file when an exception + occur. + Thu May 29 19:31:10 2014 Tanaka Akira <akr@f...> * ext/openssl/lib/openssl/ssl.rb (SSLServer#accept): Close a socket - if any exception occur. + if any exception occur. Thu May 29 05:05:29 2014 Eric Wong <e@8...> Index: lib/csv.rb =================================================================== --- lib/csv.rb (revision 46223) +++ lib/csv.rb (revision 46224) @@ -1260,7 +1260,12 @@ class CSV https://github.com/ruby/ruby/blob/trunk/lib/csv.rb#L1260 file_opts = {encoding: Encoding.default_external}.merge(file_opts) retry end - csv = new(f, options) + begin + csv = new(f, options) + rescue Exception + f.close + raise + end # handle blocks like Ruby's open(), not like the CSV library if block_given? Index: test/csv/test_features.rb =================================================================== --- test/csv/test_features.rb (revision 46223) +++ test/csv/test_features.rb (revision 46224) @@ -218,6 +218,8 @@ class TestCSV::Features < TestCSV https://github.com/ruby/ruby/blob/trunk/test/csv/test_features.rb#L218 ) end assert_equal("\r\n", zipped.row_sep) + ensure + zipped.close end if defined?(Zlib::GzipReader) def test_gzip_writer_bug_fix -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/