Skip to content

Commit faab631

Browse files
author
MarcoFalke
committed
shutdown: Stop threads before resetting ptrs
1 parent 1ef57a9 commit faab631

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/init.cpp

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -209,11 +209,7 @@ void Shutdown()
209209
// using the other before destroying them.
210210
if (peerLogic) UnregisterValidationInterface(peerLogic.get());
211211
if (g_connman) g_connman->Stop();
212-
peerLogic.reset();
213-
g_connman.reset();
214-
if (g_txindex) {
215-
g_txindex.reset();
216-
}
212+
if (g_txindex) g_txindex->Stop();
217213

218214
StopTorControl();
219215

@@ -222,6 +218,12 @@ void Shutdown()
222218
threadGroup.interrupt_all();
223219
threadGroup.join_all();
224220

221+
// After the threads that potentially access these pointers have been stopped,
222+
// destruct and reset all to nullptr.
223+
peerLogic.reset();
224+
g_connman.reset();
225+
g_txindex.reset();
226+
225227
if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) {
226228
DumpMempool();
227229
}

0 commit comments

Comments
 (0)