From cb7d48ade1debdb4d2cd00f8c7cfd5bb5e7d4ca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADt=20Ondruch?= Date: Fri, 27 Sep 2024 10:11:10 +0200 Subject: [PATCH] Ensure GC-ing closures before fork Fiddle::Closures can't be used before process is forked, otherwise test suite might crash with SELinux. This is similar treatment as is used in [Fiddle](https://github.com/ruby/fiddle/commit/1343ac7a9567665affc0e9f4bc9fd74cfd97a5fd). Fixes #1120 --- spec/ffi/callback_spec.rb | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/spec/ffi/callback_spec.rb b/spec/ffi/callback_spec.rb index 38c789e94..b94fc2afb 100644 --- a/spec/ffi/callback_spec.rb +++ b/spec/ffi/callback_spec.rb @@ -856,8 +856,8 @@ module CallbackInteropSpecs module LibTestFFI extend FFI::Library ffi_lib TestLibrary::PATH - attach_function :testCallbackVrV, :testClosureVrV, [ :pointer ], :void - attach_function :testCallbackVrV_blocking, :testClosureVrV, [ :pointer ], :void, blocking: true + @cb = attach_function :testCallbackVrV, :testClosureVrV, [ :pointer ], :void + @cb_blocking = attach_function :testCallbackVrV_blocking, :testClosureVrV, [ :pointer ], :void, blocking: true end module LibTestFiddle @@ -866,6 +866,13 @@ module LibTestFiddle extern 'void testClosureVrV(void *fp)' end + after do + LibTestFFI.instance_variable_set(:@cb, nil) + LibTestFFI.instance_variable_set(:@cb_blocking, nil) + GC.start + expect(ObjectSpace.each_object(Fiddle::Closure) {}).to eq(0) + end + def assert_callback_in_same_thread_called_once called = 0 thread = nil