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

Summary: Backport of core [[bitcoin/bitcoin#18615 | PR18615]].

Test Plan:
With TSAN:
  ninja check

Reviewers: #bitcoin_abc, majcosta

Reviewed By: #bitcoin_abc, majcosta

Differential Revision: https://reviews.bitcoinabc.org/D8639
  • Loading branch information
MarcoFalke authored and Fabcien committed Dec 9, 2020
1 parent 9461ad6 commit 3d4316d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
9 changes: 3 additions & 6 deletions src/test/txindex_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,9 @@ 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()
6 changes: 5 additions & 1 deletion src/test/validation_chainstatemanager_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <sync.h>
#include <test/util/setup_common.h>
#include <validation.h>
#include <validationinterface.h>

#include <vector>

Expand Down Expand Up @@ -100,7 +101,10 @@ 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 3d4316d

Please sign in to comment.