summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-25 09:06:16 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-03-25 09:06:16 +0000
commitd82440ff9cb17b8a32a5eeb7dd838588468b39f4 (patch)
tree9759434fa98d3d07cd81becd133efb52b6762386 /ext
parent6827f86c519421fbbcc772c83845ada36f6bc5d5 (diff)
merge revision(s) 46108,46209,46223,46297,48223,48224: [Backport #12168]
* test/openssl: Join threads. * 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. * ext/openssl/lib/openssl/ssl.rb (SSLServer#accept): Close a socket if any exception occur. * test/ruby/envutil.rb (assert_join_threads): New assertion to join multiple threads without exceptions. * test/openssl/utils.rb (start_server, server_loop): Use a pipe to stop server instead of shutdown/close a listening socket. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@54272 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/openssl/lib/openssl/ssl.rb8
-rw-r--r--ext/openssl/ossl_ssl.c24
2 files changed, 20 insertions, 12 deletions
diff --git a/ext/openssl/lib/openssl/ssl.rb b/ext/openssl/lib/openssl/ssl.rb
index ec7a223bb2..f9e561ae0d 100644
--- a/ext/openssl/lib/openssl/ssl.rb
+++ b/ext/openssl/lib/openssl/ssl.rb
@@ -305,8 +305,12 @@ module OpenSSL
ssl.sync_close = true
ssl.accept if @start_immediately
ssl
- rescue SSLError => ex
- sock.close
+ rescue Exception => ex
+ if ssl
+ ssl.close
+ else
+ sock.close
+ end
raise ex
end
end
diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c
index 8cac552101..309657ce69 100644
--- a/ext/openssl/ossl_ssl.c
+++ b/ext/openssl/ossl_ssl.c
@@ -1583,18 +1583,22 @@ static VALUE
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;