diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2019-01-09 16:22:26 -0800 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2019-10-24 19:34:15 +0900 |
commit | 7733db665ad07980afcaa5bc3fadebc0128fbdf2 (patch) | |
tree | f3be2802bd694332d0168fc5103d2f75c5b2e418 /ext | |
parent | 70ca56dedaa7ced969269ed70112ebb8da653ec2 (diff) | |
download | bundler-7733db665ad07980afcaa5bc3fadebc0128fbdf2.tar.gz |
[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
Diffstat (limited to 'ext')
-rw-r--r-- | ext/fiddle/function.c | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/ext/fiddle/function.c b/ext/fiddle/function.c index bbd73e0f0a..b3eeff16c8 100644 --- a/ext/fiddle/function.c +++ b/ext/fiddle/function.c @@ -99,6 +99,8 @@ initialize(int argc, VALUE argv[], VALUE self) 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); |