Skip to content

Commit 0fc697b

Browse files
committed
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
1 parent 8c3bc02 commit 0fc697b

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

ext/fiddle/function.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,8 @@ initialize(int argc, VALUE argv[], VALUE self)
9999
void *cfunc;
100100

101101
rb_scan_args(argc, argv, "31:", &ptr, &args, &ret_type, &abi, &kwds);
102+
rb_iv_set(self, "@closure", ptr);
103+
102104
ptr = rb_Integer(ptr);
103105
cfunc = NUM2PTR(ptr);
104106
PTR2NUM(cfunc);

0 commit comments

Comments
 (0)