[前][次][番号順一覧][スレッド一覧]

ruby-changes:32688

From: usa <ko1@a...>
Date: Thu, 30 Jan 2014 21:04:31 +0900 (JST)
Subject: [ruby-changes:32688] usa:r44767 (ruby_1_9_3): merge revision(s) 44184: [Backport #9247]

usa	2014-01-30 21:04:22 +0900 (Thu, 30 Jan 2014)

  New Revision: 44767

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44767

  Log:
    merge revision(s) 44184: [Backport #9247]
    
    * ext/socket/lib/socket.rb: Don't test $! in "ensure" clause because
      it may be set before the body.
      Reported by ko1 and mrkn.  [ruby-core:59088] [Bug #9247]
    
    * lib/cgi/core.rb: Ditto.
    
    * lib/drb/ssl.rb: Ditto.

  Modified directories:
    branches/ruby_1_9_3/
  Modified files:
    branches/ruby_1_9_3/ChangeLog
    branches/ruby_1_9_3/ext/socket/lib/socket.rb
    branches/ruby_1_9_3/lib/cgi/core.rb
    branches/ruby_1_9_3/lib/drb/ssl.rb
    branches/ruby_1_9_3/test/socket/test_socket.rb
    branches/ruby_1_9_3/version.h
Index: ruby_1_9_3/ChangeLog
===================================================================
--- ruby_1_9_3/ChangeLog	(revision 44766)
+++ ruby_1_9_3/ChangeLog	(revision 44767)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ChangeLog#L1
+Thu Jan 30 20:53:42 2014  Tanaka Akira  <akr@f...>
+
+	* ext/socket/lib/socket.rb: Don't test $! in "ensure" clause because
+	  it may be set before the body.
+	  Reported by ko1 and mrkn.  [ruby-core:59088] [Bug #9247]
+
+	* lib/cgi/core.rb: Ditto.
+
+	* lib/drb/ssl.rb: Ditto.
+
 Thu Jan 30 20:31:32 2014  NARUSE, Yui  <naruse@r...>
 
 	* process.c (rb_daemon): daemon(3) is implemented with fork(2).
Index: ruby_1_9_3/lib/cgi/core.rb
===================================================================
--- ruby_1_9_3/lib/cgi/core.rb	(revision 44766)
+++ ruby_1_9_3/lib/cgi/core.rb	(revision 44767)
@@ -478,10 +478,12 @@ class CGI https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/lib/cgi/core.rb#L478
       bufsize = 10 * 1024
       max_count = MAX_MULTIPART_COUNT
       n = 0
+      tempfiles = []
       while true
         (n += 1) < max_count or raise StandardError.new("too many parameters.")
         ## create body (StringIO or Tempfile)
         body = create_body(bufsize < content_length)
+        tempfiles << body if defined?(Tempfile) && body.kind_of?(Tempfile)
         class << body
           if method_defined?(:path)
             alias local_path path
@@ -562,6 +564,15 @@ class CGI https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/lib/cgi/core.rb#L564
       raise EOFError, "bad boundary end of body part" unless boundary_end =~ /--/
       params.default = []
       params
+    rescue Exception
+      if tempfiles
+        tempfiles.each {|t|
+          if t.path
+            t.unlink
+          end
+        }
+      end
+      raise
     end # read_multipart
     private :read_multipart
     def create_body(is_large)  #:nodoc:
Index: ruby_1_9_3/lib/drb/ssl.rb
===================================================================
--- ruby_1_9_3/lib/drb/ssl.rb	(revision 44766)
+++ ruby_1_9_3/lib/drb/ssl.rb	(revision 44767)
@@ -179,8 +179,9 @@ module DRb https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/lib/drb/ssl.rb#L179
       end
       begin
 	ssl = @config.accept(soc)
-      ensure
-        soc.close if $!
+      rescue Exception
+        soc.close
+        raise
       end
       self.class.new(uri, ssl, @config, true)
       rescue OpenSSL::SSL::SSLError
Index: ruby_1_9_3/ext/socket/lib/socket.rb
===================================================================
--- ruby_1_9_3/ext/socket/lib/socket.rb	(revision 44766)
+++ ruby_1_9_3/ext/socket/lib/socket.rb	(revision 44767)
@@ -41,13 +41,18 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L41
       sock.ipv6only! if self.ipv6?
       sock.bind local_addrinfo if local_addrinfo
       sock.connect(self)
-      if block_given?
+    rescue Exception
+      sock.close
+      raise
+    end
+    if block_given?
+      begin
         yield sock
-      else
-        sock
+      ensure
+        sock.close if !sock.closed?
       end
-    ensure
-      sock.close if !sock.closed? && (block_given? || $!)
+    else
+      sock
     end
   end
   private :connect_internal
@@ -123,13 +128,18 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L128
       sock.ipv6only! if self.ipv6?
       sock.setsockopt(:SOCKET, :REUSEADDR, 1)
       sock.bind(self)
-      if block_given?
+    rescue Exception
+      sock.close
+      raise
+    end
+    if block_given?
+      begin
         yield sock
-      else
-        sock
+      ensure
+        sock.close if !sock.closed?
       end
-    ensure
-      sock.close if !sock.closed? && (block_given? || $!)
+    else
+      sock
     end
   end
 
@@ -141,13 +151,18 @@ class Addrinfo https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L151
       sock.setsockopt(:SOCKET, :REUSEADDR, 1)
       sock.bind(self)
       sock.listen(backlog)
-      if block_given?
+    rescue Exception
+      sock.close
+      raise
+    end
+    if block_given?
+      begin
         yield sock
-      else
-        sock
+      ensure
+        sock.close if !sock.closed?
       end
-    ensure
-      sock.close if !sock.closed? && (block_given? || $!)
+    else
+      sock
     end
   end
 
@@ -278,8 +293,9 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L293
 
   # :stopdoc:
   def self.ip_sockets_port0(ai_list, reuseaddr)
+    sockets = []
     begin
-      sockets = []
+      sockets.clear
       port = nil
       ai_list.each {|ai|
         begin
@@ -300,14 +316,13 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L316
         end
       }
     rescue Errno::EADDRINUSE
-      sockets.each {|s|
-        s.close
-      }
+      sockets.each {|s| s.close }
       retry
+    rescue Exception
+      sockets.each {|s| s.close }
+      raise
     end
     sockets
-  ensure
-    sockets.each {|s| s.close if !s.closed? } if $!
   end
   class << self
     private :ip_sockets_port0
@@ -316,12 +331,15 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L331
   def self.tcp_server_sockets_port0(host)
     ai_list = Addrinfo.getaddrinfo(host, 0, nil, :STREAM, nil, Socket::AI_PASSIVE)
     sockets = ip_sockets_port0(ai_list, true)
-    sockets.each {|s|
-      s.listen(5)
-    }
+    begin
+      sockets.each {|s|
+        s.listen(5)
+      }
+    rescue Exception
+      sockets.each {|s| s.close }
+      raise
+    end
     sockets
-  ensure
-    sockets.each {|s| s.close if !s.closed? } if $! && sockets
   end
   class << self
     private :tcp_server_sockets_port0
@@ -365,9 +383,9 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L383
     if port == 0
       sockets = tcp_server_sockets_port0(host)
     else
+      last_error = nil
+      sockets = []
       begin
-        last_error = nil
-        sockets = []
         Addrinfo.foreach(host, port, nil, :STREAM, nil, Socket::AI_PASSIVE) {|ai|
           begin
             s = ai.listen
@@ -380,8 +398,9 @@ class Socket < BasicSocket https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/ext/socket/lib/socket.rb#L398
         if sockets.empty?
           raise last_error
         end
-      ensure
-        sockets.each {|s| s.close if !s.closed? } if $!
+      rescue Exception
+        sockets.each {|s| s.close }
+        raise
       end
     end
     if block_given?
Index: ruby_1_9_3/version.h
===================================================================
--- ruby_1_9_3/version.h	(revision 44766)
+++ ruby_1_9_3/version.h	(revision 44767)
@@ -1,5 +1,5 @@ https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/version.h#L1
 #define RUBY_VERSION "1.9.3"
-#define RUBY_PATCHLEVEL 509
+#define RUBY_PATCHLEVEL 510
 
 #define RUBY_RELEASE_DATE "2014-01-30"
 #define RUBY_RELEASE_YEAR 2014
Index: ruby_1_9_3/test/socket/test_socket.rb
===================================================================
--- ruby_1_9_3/test/socket/test_socket.rb	(revision 44766)
+++ ruby_1_9_3/test/socket/test_socket.rb	(revision 44767)
@@ -454,4 +454,75 @@ class TestSocket < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_1_9_3/test/socket/test_socket.rb#L454
   ensure
     server.close
   end
+
+  def test_connect_in_rescue
+    serv = Addrinfo.tcp(nil, 0).listen
+    addr = serv.connect_address
+    begin
+      raise "dummy error"
+    rescue
+      s = addr.connect
+      assert(!s.closed?)
+    end
+  ensure
+    serv.close if serv && !serv.closed?
+    s.close if s && !s.closed?
+  end
+
+  def test_bind_in_rescue
+    begin
+      raise "dummy error"
+    rescue
+      s = Addrinfo.tcp(nil, 0).bind
+      assert(!s.closed?)
+    end
+  ensure
+    s.close if s && !s.closed?
+  end
+
+  def test_listen_in_rescue
+    begin
+      raise "dummy error"
+    rescue
+      s = Addrinfo.tcp(nil, 0).listen
+      assert(!s.closed?)
+    end
+  ensure
+    s.close if s && !s.closed?
+  end
+
+  def test_udp_server_sockets_in_rescue
+    begin
+      raise "dummy error"
+    rescue
+      ss = Socket.udp_server_sockets(0)
+      ss.each {|s|
+        assert(!s.closed?)
+      }
+    end
+  ensure
+    if ss
+      ss.each {|s|
+        s.close if !s.closed?
+      }
+    end
+  end
+
+  def test_tcp_server_sockets_in_rescue
+    begin
+      raise "dummy error"
+    rescue
+      ss = Socket.tcp_server_sockets(0)
+      ss.each {|s|
+        assert(!s.closed?)
+      }
+    end
+  ensure
+    if ss
+      ss.each {|s|
+        s.close if !s.closed?
+      }
+    end
+  end
+
 end if defined?(Socket)

Property changes on: ruby_1_9_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r44184


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]