From faab63111d8f27335aa1f09c1a48da3be45135de Mon Sep 17 00:00:00 2001 From: MarcoFalke Date: Mon, 6 Aug 2018 12:08:35 -0400 Subject: shutdown: Stop threads before resetting ptrs --- src/init.cpp | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/init.cpp b/src/init.cpp index 21445929dc..5c29736913 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -209,11 +209,7 @@ void Shutdown() // using the other before destroying them. if (peerLogic) UnregisterValidationInterface(peerLogic.get()); if (g_connman) g_connman->Stop(); - peerLogic.reset(); - g_connman.reset(); - if (g_txindex) { - g_txindex.reset(); - } + if (g_txindex) g_txindex->Stop(); StopTorControl(); @@ -222,6 +218,12 @@ void Shutdown() 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(); } -- cgit v1.2.3