aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-29 10:44:59 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-29 10:44:59 +0000
commit2ad20073074f39f3ee2904a45da310ce4041aa22 (patch)
tree6e986a92398a5553db3b44abb30f108f230f61f7
parent68ac33a511929268ff5b0e05601b855a3a031b31 (diff)
downloadruby-2ad20073074f39f3ee2904a45da310ce4041aa22.tar.gz
* lib/csv.rb (CSV.open): Close the opened file when an exception occur.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46224 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog7
-rw-r--r--lib/csv.rb7
-rwxr-xr-xtest/csv/test_features.rb2
3 files changed, 14 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index d4e6a36deb..b9fe0c4f57 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,12 @@
+Thu May 29 19:42:49 2014 Tanaka Akira <akr@fsij.org>
+
+ * lib/csv.rb (CSV.open): Close the opened file when an exception
+ occur.
+
Thu May 29 19:31:10 2014 Tanaka Akira <akr@fsij.org>
* 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@80x24.org>
diff --git a/lib/csv.rb b/lib/csv.rb
index 595586a541..e1199185f9 100644
--- a/lib/csv.rb
+++ b/lib/csv.rb
@@ -1260,7 +1260,12 @@ class CSV
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?
diff --git a/test/csv/test_features.rb b/test/csv/test_features.rb
index e9700c4ef4..e31465710b 100755
--- a/test/csv/test_features.rb
+++ b/test/csv/test_features.rb
@@ -218,6 +218,8 @@ class TestCSV::Features < TestCSV
)
end
assert_equal("\r\n", zipped.row_sep)
+ ensure
+ zipped.close
end if defined?(Zlib::GzipReader)
def test_gzip_writer_bug_fix