summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-28 10:02:54 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-05-28 10:02:54 +0000
commitcbd370f669e74ca3e1953da94d4e780b7ddea391 (patch)
tree553cd6c289fe6b95eebc4d61d1aa7cc3a354be48 /lib
parent02afafb42ae4ae98140f2c79c67b948e1e6bc577 (diff)
* lib/net/imap.rb (Net::IMAP#initialize): Close the opened socket when
any exception occur. This fixes a fd leak by IMAPTest#test_imaps_post_connection_check which start_tls_session() raises an exception. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46210 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'lib')
-rw-r--r--lib/net/imap.rb67
1 files changed, 35 insertions, 32 deletions
diff --git a/lib/net/imap.rb b/lib/net/imap.rb
index 6b5ff3ee71..2e0f558054 100644
--- a/lib/net/imap.rb
+++ b/lib/net/imap.rb
@@ -1043,40 +1043,43 @@ module Net
@tagno = 0
@parser = ResponseParser.new
@sock = TCPSocket.open(@host, @port)
- if options[:ssl]
- start_tls_session(options[:ssl])
- @usessl = true
- else
- @usessl = false
- end
- @responses = Hash.new([].freeze)
- @tagged_responses = {}
- @response_handlers = []
- @tagged_response_arrival = new_cond
- @continuation_request_arrival = new_cond
- @idle_done_cond = nil
- @logout_command_tag = nil
- @debug_output_bol = true
- @exception = nil
-
- @greeting = get_response
- if @greeting.nil?
- @sock.close
- raise Error, "connection closed"
- end
- if @greeting.name == "BYE"
- @sock.close
- raise ByeResponseError, @greeting
- end
+ begin
+ if options[:ssl]
+ start_tls_session(options[:ssl])
+ @usessl = true
+ else
+ @usessl = false
+ end
+ @responses = Hash.new([].freeze)
+ @tagged_responses = {}
+ @response_handlers = []
+ @tagged_response_arrival = new_cond
+ @continuation_request_arrival = new_cond
+ @idle_done_cond = nil
+ @logout_command_tag = nil
+ @debug_output_bol = true
+ @exception = nil
- @client_thread = Thread.current
- @receiver_thread = Thread.start {
- begin
- receive_responses
- rescue Exception
+ @greeting = get_response
+ if @greeting.nil?
+ raise Error, "connection closed"
end
- }
- @receiver_thread_terminating = false
+ if @greeting.name == "BYE"
+ raise ByeResponseError, @greeting
+ end
+
+ @client_thread = Thread.current
+ @receiver_thread = Thread.start {
+ begin
+ receive_responses
+ rescue Exception
+ end
+ }
+ @receiver_thread_terminating = false
+ rescue Exception
+ @sock.close
+ raise
+ end
end
def receive_responses