@@ -116,10 +116,9 @@ static void
116116ossl_x509store_mark (void * ptr )
117117{
118118 X509_STORE * store = ptr ;
119- // Note: this reference is stored as @verify_callback so we don't need to mark it.
120- // However we do need to ensure GC compaction won't move it, hence why
121- // we call rb_gc_mark here.
122- rb_gc_mark ((VALUE )X509_STORE_get_ex_data (store , store_ex_verify_cb_idx ));
119+ VALUE verify_cb =
120+ (VALUE )X509_STORE_get_ex_data (store , store_ex_verify_cb_idx );
121+ rb_gc_mark_movable (verify_cb );
123122}
124123
125124static void
@@ -128,12 +127,26 @@ ossl_x509store_free(void *ptr)
128127 X509_STORE_free (ptr );
129128}
130129
130+ static void
131+ ossl_x509store_compact (void * ptr )
132+ {
133+ X509_STORE * store = ptr ;
134+ VALUE verify_cb =
135+ (VALUE )X509_STORE_get_ex_data (store , store_ex_verify_cb_idx );
136+ if (verify_cb ) {
137+ (void )X509_STORE_set_ex_data (store , store_ex_verify_cb_idx ,
138+ (void * )rb_gc_location (verify_cb ));
139+ }
140+ }
141+
131142static const rb_data_type_t ossl_x509store_type = {
132- "OpenSSL/X509/STORE" ,
133- {
134- ossl_x509store_mark , ossl_x509store_free ,
143+ .wrap_struct_name = "OpenSSL/X509/STORE" ,
144+ .function = {
145+ .dmark = ossl_x509store_mark ,
146+ .dfree = ossl_x509store_free ,
147+ .dcompact = ossl_x509store_compact ,
135148 },
136- 0 , 0 , RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED ,
149+ . flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED ,
137150};
138151
139152/*
@@ -570,10 +583,9 @@ static void
570583ossl_x509stctx_mark (void * ptr )
571584{
572585 X509_STORE_CTX * ctx = ptr ;
573- // Note: this reference is stored as @verify_callback so we don't need to mark it.
574- // However we do need to ensure GC compaction won't move it, hence why
575- // we call rb_gc_mark here.
576- rb_gc_mark ((VALUE )X509_STORE_CTX_get_ex_data (ctx , stctx_ex_verify_cb_idx ));
586+ VALUE verify_cb =
587+ (VALUE )X509_STORE_CTX_get_ex_data (ctx , stctx_ex_verify_cb_idx );
588+ rb_gc_mark_movable (verify_cb );
577589}
578590
579591static void
@@ -585,12 +597,26 @@ ossl_x509stctx_free(void *ptr)
585597 X509_STORE_CTX_free (ctx );
586598}
587599
600+ static void
601+ ossl_x509stctx_compact (void * ptr )
602+ {
603+ X509_STORE_CTX * ctx = ptr ;
604+ VALUE verify_cb =
605+ (VALUE )X509_STORE_CTX_get_ex_data (ctx , stctx_ex_verify_cb_idx );
606+ if (verify_cb ) {
607+ (void )X509_STORE_CTX_set_ex_data (ctx , stctx_ex_verify_cb_idx ,
608+ (void * )rb_gc_location (verify_cb ));
609+ }
610+ }
611+
588612static const rb_data_type_t ossl_x509stctx_type = {
589- "OpenSSL/X509/STORE_CTX" ,
590- {
591- ossl_x509stctx_mark , ossl_x509stctx_free ,
613+ .wrap_struct_name = "OpenSSL/X509/STORE_CTX" ,
614+ .function = {
615+ .dmark = ossl_x509stctx_mark ,
616+ .dfree = ossl_x509stctx_free ,
617+ .dcompact = ossl_x509stctx_compact ,
592618 },
593- 0 , 0 , RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED ,
619+ . flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED ,
594620};
595621
596622static VALUE
0 commit comments