diff --git a/src/init.cpp b/src/init.cpp --- a/src/init.cpp +++ b/src/init.cpp @@ -215,10 +215,8 @@ if (g_connman) { g_connman->Stop(); } - peerLogic.reset(); - g_connman.reset(); if (g_txindex) { - g_txindex.reset(); + g_txindex->Stop(); } StopTorControl(); @@ -228,6 +226,12 @@ threadGroup.interrupt_all(); threadGroup.join_all(); + // After the threads that potentially access these pointers have been + // stopped, destruct and reset all to nullptr. + peerLogic.reset(); + g_connman.reset(); + g_txindex.reset(); + if (g_is_mempool_loaded && gArgs.GetArg("-persistmempool", DEFAULT_PERSIST_MEMPOOL)) { DumpMempool();