diff options
author | Sutou Kouhei <kou@clear-code.com> | 2022-09-09 23:59:41 +0900 |
---|---|---|
committer | Hiroshi SHIBATA <hsbt@ruby-lang.org> | 2022-10-07 15:18:49 +0900 |
commit | 6d01b66764b6dd3fc61c297bd1ec973f8ea686aa (patch) | |
tree | f0db34c7a92181f1cf861b633ca05213a8f0bfb4 /test/fiddle | |
parent | 1b7c5c394f14e1a7aebbaf14b7d681733d1d97c2 (diff) | |
download | ruby-6d01b66764b6dd3fc61c297bd1ec973f8ea686aa.tar.gz |
[ruby/fiddle] test: ensure GC-ing closures
GitHub: fix GH-102
We can't use Fiddle::Closure before we fork the process. If we do it,
the process may be crashed with SELinux.
See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091
for details.
Reported by Vít Ondruch. Thanks!!!
https://github.com/ruby/fiddle/commit/1343ac7a95
Diffstat (limited to 'test/fiddle')
-rw-r--r-- | test/fiddle/test_closure.rb | 11 | ||||
-rw-r--r-- | test/fiddle/test_func.rb | 6 | ||||
-rw-r--r-- | test/fiddle/test_function.rb | 7 | ||||
-rw-r--r-- | test/fiddle/test_import.rb | 6 |
4 files changed, 24 insertions, 6 deletions
diff --git a/test/fiddle/test_closure.rb b/test/fiddle/test_closure.rb index 9e748bf5ee..1a7c41fd95 100644 --- a/test/fiddle/test_closure.rb +++ b/test/fiddle/test_closure.rb @@ -6,6 +6,14 @@ end module Fiddle class TestClosure < Fiddle::TestCase + def teardown + super + # Ensure freeing all closures. + # See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 . + GC.start + assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {}) + end + def test_argument_errors assert_raise(TypeError) do Closure.new(TYPE_INT, TYPE_INT) @@ -103,6 +111,9 @@ module Fiddle func = Function.new(clos, [t], t) assert_equal(v, func.call(v)) assert_equal(arg, v, n) + ensure + clos = nil + func = nil end end end diff --git a/test/fiddle/test_func.rb b/test/fiddle/test_func.rb index 44893017e8..45fed916ba 100644 --- a/test/fiddle/test_func.rb +++ b/test/fiddle/test_func.rb @@ -79,6 +79,12 @@ module Fiddle qsort.call(buff, buff.size, 1, cb) end assert_equal("1349", buff, bug4929) + ensure + # Ensure freeing all closures. + # See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 . + cb = nil + GC.start + assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {}) end def test_snprintf diff --git a/test/fiddle/test_function.rb b/test/fiddle/test_function.rb index 8ac4f60aa3..0a1159b7bc 100644 --- a/test/fiddle/test_function.rb +++ b/test/fiddle/test_function.rb @@ -15,6 +15,13 @@ module Fiddle end end + def teardown + # Ensure freeing all closures. + # See https://github.com/ruby/fiddle/issues/102#issuecomment-1241763091 . + GC.start + assert_equal(0, ObjectSpace.each_object(Fiddle::Closure) {}) + end + def test_default_abi func = Function.new(@libm['sin'], [TYPE_DOUBLE], TYPE_DOUBLE) assert_equal Function::DEFAULT, func.abi diff --git a/test/fiddle/test_import.rb b/test/fiddle/test_import.rb index afa8df9e00..831c1d310f 100644 --- a/test/fiddle/test_import.rb +++ b/test/fiddle/test_import.rb @@ -22,7 +22,6 @@ module Fiddle extern "int fprintf(FILE*, char*)" rescue nil extern "int gettimeofday(timeval*, timezone*)" rescue nil - BoundQsortCallback = bind("void *bound_qsort_callback(void*, void*)"){|ptr1,ptr2| ptr1[0] <=> ptr2[0]} Timeval = struct [ "long tv_sec", "long tv_usec", @@ -59,11 +58,6 @@ module Fiddle ] } ] - - CallCallback = bind("void call_callback(void*, void*)"){ | ptr1, ptr2| - f = Function.new(ptr1.to_i, [TYPE_VOIDP], TYPE_VOID) - f.call(ptr2) - } end class TestImport < TestCase |