ruby-changes:68503
From: Kazuki <ko1@a...>
Date: Sat, 16 Oct 2021 19:53:28 +0900 (JST)
Subject: [ruby-changes:68503] ca28545b51 (master): [ruby/openssl] ssl: explicitly call rb_gc_mark() against SSLContext/SSLSocket objects
https://git.ruby-lang.org/ruby.git/commit/?id=ca28545b51 From ca28545b517057613f57e4814622e553d6fae442 Mon Sep 17 00:00:00 2001 From: Kazuki Yamaguchi <k@r...> Date: Thu, 14 Oct 2021 15:50:02 +0900 Subject: [ruby/openssl] ssl: explicitly call rb_gc_mark() against SSLContext/SSLSocket objects We store the reverse reference to the Ruby object in the OpenSSL struct for use from OpenSSL callback functions. To prevent the Ruby object from being relocated by GC.compact, we must "pin" it by calling rb_gc_mark(). https://github.com/ruby/openssl/commit/022b7ceada --- ext/openssl/ossl_ssl.c | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/ext/openssl/ossl_ssl.c b/ext/openssl/ossl_ssl.c index 1b7586cc88..9edf8b3796 100644 --- a/ext/openssl/ossl_ssl.c +++ b/ext/openssl/ossl_ssl.c @@ -56,6 +56,13 @@ static int ossl_ssl_ex_vcb_idx; https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L56 static int ossl_ssl_ex_ptr_idx; static int ossl_sslctx_ex_ptr_idx; +static void +ossl_sslctx_mark(void *ptr) +{ + SSL_CTX *ctx = ptr; + rb_gc_mark((VALUE)SSL_CTX_get_ex_data(ctx, ossl_sslctx_ex_ptr_idx)); +} + static void ossl_sslctx_free(void *ptr) { @@ -65,7 +72,7 @@ ossl_sslctx_free(void *ptr) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L72 static const rb_data_type_t ossl_sslctx_type = { "OpenSSL/SSL/CTX", { - 0, ossl_sslctx_free, + ossl_sslctx_mark, ossl_sslctx_free, }, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, }; @@ -1433,6 +1440,14 @@ ssl_started(SSL *ssl) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1440 return SSL_get_fd(ssl) >= 0; } +static void +ossl_ssl_mark(void *ptr) +{ + SSL *ssl = ptr; + rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_ptr_idx)); + rb_gc_mark((VALUE)SSL_get_ex_data(ssl, ossl_ssl_ex_vcb_idx)); +} + static void ossl_ssl_free(void *ssl) { @@ -1442,7 +1457,7 @@ ossl_ssl_free(void *ssl) https://github.com/ruby/ruby/blob/trunk/ext/openssl/ossl_ssl.c#L1457 const rb_data_type_t ossl_ssl_type = { "OpenSSL/SSL", { - 0, ossl_ssl_free, + ossl_ssl_mark, ossl_ssl_free, }, 0, 0, RUBY_TYPED_FREE_IMMEDIATELY, }; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/