Skip to content

Commit 4bd6bc5

Browse files
author
MarcoFalke
committed
Merge #18615: test: Avoid accessing free'd memory in validation_chainstatemanager_tests
fa176e2 test: Avoid accessing free'd memory in validation_chainstatemanager_tests (MarcoFalke) Pull request description: ACKs for top commit: ryanofsky: Code review ACK fa176e2, though if you have to update this again, would suggest separating txindex test cleanup and the chainstatemanager test fix in separate commits, or identifying which part of the change is the bugfix fix in the commit description. Also to clean up the txindex test it might make sense to call SyncWithValidationInterfaceQueue in the test destructor to prevent nondeterminism in other tests Tree-SHA512: 34c5dca283a7c205cd42b6aa59f00a71fd1bd980bc3d6640a18b280be11470bfabb2fd8c93fadde6fb8e084bcf96c80ec3aa72bbccccfde8a8260d173eaad08f
2 parents 20c0e2e + fa176e2 commit 4bd6bc5

File tree

2 files changed

+8
-9
lines changed

2 files changed

+8
-9
lines changed

src/test/txindex_tests.cpp

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,8 @@ BOOST_FIXTURE_TEST_CASE(txindex_initial_sync, TestChain100Setup)
7070
// shutdown sequence (c.f. Shutdown() in init.cpp)
7171
txindex.Stop();
7272

73-
// txindex job may be scheduled, so stop scheduler before destructing
74-
m_node.scheduler->stop();
75-
threadGroup.interrupt_all();
76-
threadGroup.join_all();
77-
78-
// Rest of shutdown sequence and destructors happen in ~TestingSetup()
73+
// Let scheduler events finish running to avoid accessing any memory related to txindex after it is destructed
74+
SyncWithValidationInterfaceQueue();
7975
}
8076

8177
BOOST_AUTO_TEST_SUITE_END()

src/test/validation_chainstatemanager_tests.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
// file COPYING or http://www.opensource.org/licenses/mit-license.php.
44
//
55
#include <chainparams.h>
6-
#include <random.h>
7-
#include <uint256.h>
86
#include <consensus/validation.h>
7+
#include <random.h>
98
#include <sync.h>
109
#include <test/util/setup_common.h>
10+
#include <uint256.h>
1111
#include <validation.h>
12+
#include <validationinterface.h>
1213

1314
#include <vector>
1415

@@ -97,7 +98,9 @@ BOOST_AUTO_TEST_CASE(chainstatemanager)
9798
exp_tip = c1.m_chain.Tip();
9899
BOOST_CHECK_EQUAL(validated_tip, exp_tip);
99100

100-
// Avoid triggering the address sanitizer.
101+
// Let scheduler events finish running to avoid accessing memory that is going to be unloaded
102+
SyncWithValidationInterfaceQueue();
103+
101104
WITH_LOCK(::cs_main, manager.Unload());
102105
}
103106

0 commit comments

Comments
 (0)