Skip to content

Commit fa176e2

Browse files
author
MarcoFalke
committed
test: Avoid accessing free'd memory in validation_chainstatemanager_tests
1 parent a2b282c commit fa176e2

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)