File tree 2 files changed +35
-2
lines changed
2 files changed +35
-2
lines changed Original file line number Diff line number Diff line change @@ -497,8 +497,11 @@ print_mem_leaks(VALUE self)
497
497
int ret ;
498
498
#endif
499
499
500
- BN_CTX_free (ossl_bn_ctx );
501
- ossl_bn_ctx = NULL ;
500
+ #ifndef HAVE_RB_EXT_RACTOR_SAFE
501
+ // for Ruby 2.x
502
+ void ossl_bn_ctx_free (void ); // ossl_bn.c
503
+ ossl_bn_ctx_free ();
504
+ #endif
502
505
503
506
#if OPENSSL_VERSION_NUMBER >= 0x10100000
504
507
ret = CRYPTO_mem_leaks_fp (stderr );
Original file line number Diff line number Diff line change 9
9
*/
10
10
/* modified by Michal Rokos <[email protected] > */
11
11
#include "ossl.h"
12
+
13
+ #if HAVE_RB_EXT_RACTOR_SAFE
12
14
#include <ruby/ractor.h>
15
+ #endif
13
16
14
17
#define NewBN (klass ) \
15
18
TypedData_Wrap_Struct((klass), &ossl_bn_type, 0)
@@ -152,6 +155,7 @@ ossl_bn_value_ptr(volatile VALUE *ptr)
152
155
* Private
153
156
*/
154
157
158
+ #if HAVE_RB_EXT_RACTOR_SAFE
155
159
void
156
160
ossl_bn_ctx_free (void * ptr )
157
161
{
@@ -180,6 +184,28 @@ ossl_bn_ctx_get(void)
180
184
}
181
185
return ctx ;
182
186
}
187
+ #else
188
+ // for ruby 2.x
189
+ static BN_CTX * gv_ossl_bn_ctx ;
190
+
191
+ BN_CTX *
192
+ ossl_bn_ctx_get (void )
193
+ {
194
+ if (gv_ossl_bn_ctx == NULL ) {
195
+ if (!(gv_ossl_bn_ctx = BN_CTX_new ())) {
196
+ ossl_raise (rb_eRuntimeError , "Cannot init BN_CTX" );
197
+ }
198
+ }
199
+ return gv_ossl_bn_ctx ;
200
+ }
201
+
202
+ void
203
+ ossl_bn_ctx_free (void )
204
+ {
205
+ BN_CTX_free (gv_ossl_bn_ctx );
206
+ gv_ossl_bn_ctx = NULL ;
207
+ }
208
+ #endif
183
209
184
210
static VALUE
185
211
ossl_bn_alloc (VALUE klass )
@@ -1116,7 +1142,11 @@ Init_ossl_bn(void)
1116
1142
eOSSLError = rb_define_class_under (mOSSL , "OpenSSLError" , rb_eStandardError );
1117
1143
#endif
1118
1144
1145
+ #ifdef HAVE_RB_EXT_RACTOR_SAFE
1119
1146
ossl_bn_ctx_key = rb_ractor_local_storage_ptr_newkey (& ossl_bn_ctx_key_type );
1147
+ #else
1148
+ ossl_bn_ctx_get ();
1149
+ #endif
1120
1150
1121
1151
eBNError = rb_define_class_under (mOSSL , "BNError" , eOSSLError );
1122
1152
You can’t perform that action at this time.
0 commit comments