From edcaa405bfa83c2b3c08c4541c87c93752997c50 Mon Sep 17 00:00:00 2001 From: Zachery Hostens Date: Fri, 15 Nov 2024 06:22:35 -0600 Subject: [PATCH] RUBY-3557 Mark SecureRandom as Global (#341) SecureRandom needs to be marked global so that it does not possibly get moved during GC compaction. --- ext/bson/util.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/ext/bson/util.c b/ext/bson/util.c index 2bcfada16..66810e476 100644 --- a/ext/bson/util.c +++ b/ext/bson/util.c @@ -170,6 +170,9 @@ VALUE pvt_load_secure_random(VALUE _arg) { pvt_SecureRandom = rb_const_get(rb_cObject, rb_intern("SecureRandom")); pvt_has_random_number = rb_respond_to(pvt_SecureRandom, rb_intern("random_number")); + // mark SecureRandom so it does not get moved + rb_global_variable(&pvt_SecureRandom); + return Qnil; }