Skip to content

Commit

Permalink
test: Avoid accessing free'd memory in validation_chainstatemanager_t…
Browse files Browse the repository at this point in the history
…ests
  • Loading branch information
MarcoFalke committed Apr 15, 2020
1 parent a2b282c commit fa176e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 9 deletions.
8 changes: 2 additions & 6 deletions src/test/txindex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 6 additions & 3 deletions src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
//
#include <chainparams.h>
#include <random.h>
#include <uint256.h>
#include <consensus/validation.h>
#include <random.h>
#include <sync.h>
#include <test/util/setup_common.h>
#include <uint256.h>
#include <validation.h>
#include <validationinterface.h>

#include <vector>

Expand Down Expand Up @@ -97,7 +98,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());
}

Expand Down

0 comments on commit fa176e2

Please sign in to comment.