From 8e50fac61653b6c2fe492e5e5efd4e0bfaff90b7 Mon Sep 17 00:00:00 2001 From: Xinhao Yuan Date: Fri, 7 Mar 2025 07:38:25 -0800 Subject: [PATCH] Tear down fixture in the controller mode as early as possible. PiperOrigin-RevId: 734553075 --- fuzztest/internal/centipede_adaptor.cc | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/fuzztest/internal/centipede_adaptor.cc b/fuzztest/internal/centipede_adaptor.cc index 9e004e64..3fede7b1 100644 --- a/fuzztest/internal/centipede_adaptor.cc +++ b/fuzztest/internal/centipede_adaptor.cc @@ -607,6 +607,7 @@ bool CentipedeFuzzerAdaptor::Run(int* argc, char*** argv, RunMode mode, runtime_.EnableReporter(&fuzzer_impl_.stats_, [] { return absl::Now(); }); } fuzzer_impl_.fixture_driver_->SetUpFuzzTest(); + bool to_tear_down_fuzz_test = true; const int result = ([&]() { if (runtime_.skipping_requested()) { absl::FPrintF(GetStderr(), @@ -629,6 +630,9 @@ bool CentipedeFuzzerAdaptor::Run(int* argc, char*** argv, RunMode mode, if (fuzzer_impl_.ReplayInputsIfAvailable(configuration)) return 0; // `ReplayInputsIfAvailable` overwrites the run mode - revert it back. runtime_.SetRunMode(mode); + // Tear down fixture early to avoid interfering with the runners. + fuzzer_impl_.fixture_driver_->TearDownFuzzTest(); + to_tear_down_fuzz_test = false; // Run as the fuzzing engine. std::unique_ptr workdir; if (configuration.corpus_database.empty() || mode == RunMode::kUnitTest) @@ -692,7 +696,9 @@ bool CentipedeFuzzerAdaptor::Run(int* argc, char*** argv, RunMode mode, } return centipede::CentipedeMain(env, factory); })(); - fuzzer_impl_.fixture_driver_->TearDownFuzzTest(); + if (to_tear_down_fuzz_test) { + fuzzer_impl_.fixture_driver_->TearDownFuzzTest(); + } return result == 0; }