From a0323925d92012eedf15fc0edbe01cd7d2b318e7 Mon Sep 17 00:00:00 2001 From: Matt Palmer Date: Fri, 7 Oct 2022 11:27:54 +1100 Subject: [PATCH] Avoid potential crashes due to key data getting GC'd --- ruby/lib/enquo/root.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ruby/lib/enquo/root.rb b/ruby/lib/enquo/root.rb index fa81758..4c9ab2a 100644 --- a/ruby/lib/enquo/root.rb +++ b/ruby/lib/enquo/root.rb @@ -6,6 +6,10 @@ def self.new(key) _new_from_static_root_key(key) else raise ArgumentError, "key must be a root key provider object (got a #{key.class})" + end.tap do |k| + # DIRTY HACK ALERT: take a reference to the key so it doesn't get GC'd + # If someone can come up with a better way to acheive this, I'm all ears + k.instance_variable_set(:@_key, key) end end