From 72e957cb038668e025b6c7210430d2e8d761fcd8 Mon Sep 17 00:00:00 2001 From: Mike Dalessio Date: Wed, 20 Dec 2023 08:55:53 -0500 Subject: [PATCH] Set RUBY_FREE_AT_EXIT for Ruby >= 3.3.0 For more information, see: - https://bugs.ruby-lang.org/issues/19993 - https://github.com/ruby/ruby/pull/8868 - https://github.com/ruby/ruby/pull/9302 --- lib/ruby_memcheck/test_task_reporter.rb | 1 + .../shared_test_task_reporter_tests.rb | 14 +++++++++++++- 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/ruby_memcheck/test_task_reporter.rb b/lib/ruby_memcheck/test_task_reporter.rb index 0803277..bde2321 100644 --- a/lib/ruby_memcheck/test_task_reporter.rb +++ b/lib/ruby_memcheck/test_task_reporter.rb @@ -21,6 +21,7 @@ def run_ruby_with_valgrind(&block) def setup ENV["RUBY_MEMCHECK_LOADED_FEATURES_FILE"] = File.expand_path(configuration.loaded_features_file) ENV["RUBY_MEMCHECK_RUNNING"] = "1" + ENV["RUBY_FREE_AT_EXIT"] = "1" end def report_valgrind_errors diff --git a/test/ruby_memcheck/shared_test_task_reporter_tests.rb b/test/ruby_memcheck/shared_test_task_reporter_tests.rb index b81e654..f00a011 100644 --- a/test/ruby_memcheck/shared_test_task_reporter_tests.rb +++ b/test/ruby_memcheck/shared_test_task_reporter_tests.rb @@ -223,7 +223,7 @@ def test_test_helper_is_loaded end end - def test_envionment_variable_RUBY_MEMCHECK_RUNNING + def test_environment_variable_RUBY_MEMCHECK_RUNNING Tempfile.create do |tempfile| ok = run_with_memcheck(<<~RUBY, raise_on_failure: false) File.write(#{tempfile.path.inspect}, ENV["RUBY_MEMCHECK_RUNNING"]) @@ -235,6 +235,18 @@ def test_envionment_variable_RUBY_MEMCHECK_RUNNING end end + def test_environment_variable_RUBY_FREE_AT_EXIT + Tempfile.create do |tempfile| + ok = run_with_memcheck(<<~RUBY, raise_on_failure: false) + File.write(#{tempfile.path.inspect}, ENV["RUBY_FREE_AT_EXIT"]) + RUBY + + assert(ok) + assert_empty(@test_task.reporter.errors) + assert_includes(tempfile.read, "1") + end + end + def test_configration_binary_name build_configuration(binary_name: "ruby_memcheck_c_test_one") error = assert_raises do