[前][次][番号順一覧][スレッド一覧]

ruby-changes:58398

From: Aaron <ko1@a...>
Date: Thu, 24 Oct 2019 19:36:17 +0900 (JST)
Subject: [ruby-changes:58398] 7733db665a (master): [ruby/fiddle] Fiddle::Function must maintain a reference to the closure

https://git.ruby-lang.org/ruby.git/commit/?id=7733db665a

From 7733db665ad07980afcaa5bc3fadebc0128fbdf2 Mon Sep 17 00:00:00 2001
From: Aaron Patterson <aaron.patterson@g...>
Date: Wed, 9 Jan 2019 16:22:26 -0800
Subject: [ruby/fiddle] Fiddle::Function must maintain a reference to the
 closure

If the first parameter to Fiddle::Function is a closure object (rather
than an interger), `rb_Integer` will cast it to an integer but not
maintain a reference to the closure.  Then if the closure gets GC'd, we
have a segv.  This commit keeps a reference to the original parameter to
initialize so that the object will not be GC'd.

Fixes: https://bugs.ruby-lang.org/issues/13286

https://github.com/ruby/fiddle/commit/0fc697bbc5

diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c
index bbd73e0..b3eeff1 100644
--- a/ext/fiddle/function.c
+++ b/ext/fiddle/function.c
@@ -99,6 +99,8 @@ initialize(int argc, VALUE argv[], VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/fiddle/function.c#L99
     void *cfunc;
 
     rb_scan_args(argc, argv, "31:", &ptr, &args, &ret_type, &abi, &kwds);
+    rb_iv_set(self, "@closure", ptr);
+
     ptr = rb_Integer(ptr);
     cfunc = NUM2PTR(ptr);
     PTR2NUM(cfunc);
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]