* 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
This commit is contained in:
akr 2014-05-28 10:02:54 +00:00
parent 02afafb42a
commit cbd370f669
3 changed files with 56 additions and 45 deletions

View File

@ -1,3 +1,10 @@
Wed May 28 19:00:31 2014 Tanaka Akira <akr@fsij.org>
* 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.
Wed May 28 18:06:13 2014 Tanaka Akira <akr@fsij.org>
* ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work

View File

@ -1043,6 +1043,7 @@ module Net
@tagno = 0
@parser = ResponseParser.new
@sock = TCPSocket.open(@host, @port)
begin
if options[:ssl]
start_tls_session(options[:ssl])
@usessl = true
@ -1061,11 +1062,9 @@ module Net
@greeting = get_response
if @greeting.nil?
@sock.close
raise Error, "connection closed"
end
if @greeting.name == "BYE"
@sock.close
raise ByeResponseError, @greeting
end
@ -1077,6 +1076,10 @@ module Net
end
}
@receiver_thread_terminating = false
rescue Exception
@sock.close
raise
end
end
def receive_responses

View File

@ -505,6 +505,7 @@ class IMAPTest < Test::Unit::TestCase
ths = Thread.start do
begin
sock = server.accept
begin
sock.print("* OK test server\r\n")
sock.gets
sock.print("RUBY0001 OK completed\r\n")
@ -517,7 +518,7 @@ class IMAPTest < Test::Unit::TestCase
OpenSSL::X509::Certificate.new(f)
}
sock = OpenSSL::SSL::SSLSocket.new(sock, ctx)
begin
sock.sync_close = true
sock.accept
sock.gets
sock.print("* BYE terminating connection\r\n")