ruby-changes:34128
From: akr <ko1@a...>
Date: Wed, 28 May 2014 18:09:35 +0900 (JST)
Subject: [ruby-changes:34128] akr:r46209 (trunk): * ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work
akr 2014-05-28 18:09:26 +0900 (Wed, 28 May 2014) New Revision: 46209 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=46209 Log: * ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work when SSL is not started. This fix the fd leak by test_https_proxy_authentication in test/net/http/test_https_proxy.rb. Modified files: trunk/ChangeLog trunk/ext/openssl/ossl_ssl.c trunk/test/openssl/test_ssl.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 46208) +++ ChangeLog (revision 46209) @@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed May 28 18:06:13 2014 Tanaka Akira <akr@f...> + + * ext/openssl/ossl_ssl.c (ossl_ssl_close): Fix sync_close to work + when SSL is not started. + This fix the fd leak by test_https_proxy_authentication in + test/net/http/test_https_proxy.rb. + Wed May 28 10:29:28 2014 Eric Wong <e@8...> * vm.c (rb_vm_living_threads_foreach): remove function Index: ext/openssl/ossl_ssl.c =================================================================== --- ext/openssl/ossl_ssl.c (revision 46208) +++ ext/openssl/ossl_ssl.c (revision 46209) @@ -1566,18 +1566,22 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1566 ossl_ssl_close(VALUE self) { SSL *ssl; + VALUE io; - ossl_ssl_data_get_struct(self, ssl); + /* ossl_ssl_data_get_struct() is not usable here because it may return + * from this function; */ - if (ssl) { - VALUE io = ossl_ssl_get_io(self); - if (!RTEST(rb_funcall(io, rb_intern("closed?"), 0))) { - ossl_ssl_shutdown(ssl); - SSL_free(ssl); - DATA_PTR(self) = NULL; - if (RTEST(ossl_ssl_get_sync_close(self))) - rb_funcall(io, rb_intern("close"), 0); - } + Data_Get_Struct(self, SSL, ssl); + + io = ossl_ssl_get_io(self); + if (!RTEST(rb_funcall(io, rb_intern("closed?"), 0))) { + if (ssl) { + ossl_ssl_shutdown(ssl); + SSL_free(ssl); + } + DATA_PTR(self) = NULL; + if (RTEST(ossl_ssl_get_sync_close(self))) + rb_funcall(io, rb_intern("close"), 0); } return Qnil; Index: test/openssl/test_ssl.rb =================================================================== --- test/openssl/test_ssl.rb (revision 46208) +++ test/openssl/test_ssl.rb (revision 46209) @@ -680,6 +680,15 @@ end https://github.com/ruby/ruby/blob/trunk/test/openssl/test_ssl.rb#L680 } end + def test_sync_close_without_connect + Socket.open(:INET, :STREAM) {|s| + ssl = OpenSSL::SSL::SSLSocket.new(s) + ssl.sync_close = true + ssl.close + assert(s.closed?) + } + end + private def start_server_version(version, ctx_proc=nil, server_proc=nil, &blk) -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/