From 2ad20073074f39f3ee2904a45da310ce4041aa22 Mon Sep 17 00:00:00 2001 From: akr Date: Thu, 29 May 2014 10:44:59 +0000 Subject: * 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 --- lib/csv.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'lib') 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? -- cgit v1.2.3