From c1ed4cbdaeb1dbf0d9d4af1b84b454a8c8aefde5 Mon Sep 17 00:00:00 2001 From: Kittywhiskers Van Gogh <63189531+kittywhiskers@users.noreply.github.com> Date: Sun, 12 Apr 2020 20:22:38 -0400 Subject: [PATCH] merge bitcoin#18615: Avoid accessing free'd memory in validation_chainstatemanager_tests --- src/test/txindex_tests.cpp | 8 ++------ src/test/validation_chainstatemanager_tests.cpp | 9 ++++++--- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/txindex_tests.cpp b/src/test/txindex_tests.cpp index 6616ea1be0..6f08647e83 100644 --- a/src/test/txindex_tests.cpp +++ b/src/test/txindex_tests.cpp @@ -70,12 +70,8 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup) // shutdown sequence (c.f. Shutdown() in init.cpp) txindex.Stop(); - // txindex job may be scheduled, so stop scheduler before destructing - m_node.scheduler->stop(); - threadGroup.interrupt_all(); - threadGroup.join_all(); - - // Rest of shutdown sequence and destructors happen in ~TestingSetup() + // Let scheduler events finish running to avoid accessing any memory related to txindex after it is destructed + SyncWithValidationInterfaceQueue(); } BOOST_AUTO_TEST_SUITE_END() diff --git a/src/test/validation_chainstatemanager_tests.cpp b/src/test/validation_chainstatemanager_tests.cpp index c43123a0a7..dd6a5250ab 100644 --- a/src/test/validation_chainstatemanager_tests.cpp +++ b/src/test/validation_chainstatemanager_tests.cpp @@ -3,13 +3,14 @@ // file COPYING or http://www.opensource.org/licenses/mit-license.php. // #include -#include #include -#include #include +#include #include #include +#include #include +#include #include @@ -102,7 +103,9 @@ BOOST_AUTO_TEST_CASE(chainstatemanager) exp_tip = c1.m_chain.Tip(); BOOST_CHECK_EQUAL(validated_tip, exp_tip); - // Avoid triggering the address sanitizer. + // Let scheduler events finish running to avoid accessing memory that is going to be unloaded + SyncWithValidationInterfaceQueue(); + WITH_LOCK(::cs_main, manager.Unload()); }