From 82ca5fdbb8b2a92585086b501dbbeb9700b3b655 Mon Sep 17 00:00:00 2001 From: Tim Flynn Date: Sat, 12 Nov 2016 06:14:50 -0500 Subject: [PATCH] CGovernanceManager initialization fix (#1138) * Fix CGovernanceManager initialization problem * Added logging messages for cases where CGovernanceManager receives a message while not synced * Prevent potential NULL pointer dereference --- src/governance.cpp | 14 ++++++++++++-- src/init.cpp | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/src/governance.cpp b/src/governance.cpp index f923eadbe..146a596eb 100644 --- a/src/governance.cpp +++ b/src/governance.cpp @@ -129,7 +129,10 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C LOCK(cs); // MAKE SURE WE HAVE A VALID REFERENCE TO THE TIP BEFORE CONTINUING - if(!pCurrentBlockIndex) return; + if(!pCurrentBlockIndex) { + LogPrintf("CGovernanceManager::ProcessMessage MNGOVERNANCEOBJECT -- pCurrentBlockIndex is NULL\n"); + return; + } CGovernanceObject govobj; vRecv >> govobj; @@ -172,7 +175,10 @@ void CGovernanceManager::ProcessMessage(CNode* pfrom, std::string& strCommand, C else if (strCommand == NetMsgType::MNGOVERNANCEOBJECTVOTE) { // Ignore such messages until masternode list is synced - if(!masternodeSync.IsMasternodeListSynced()) return; + if(!masternodeSync.IsMasternodeListSynced()) { + LogPrint("gobject", "CGovernanceManager::ProcessMessage MNGOVERNANCEOBJECTVOTE -- masternode list not synced\n"); + return; + } CGovernanceVote vote; vRecv >> vote; @@ -1125,6 +1131,10 @@ void CGovernanceManager::UpdatedBlockTip(const CBlockIndex *pindex) // On the other hand it should be safe for us to access pindex without holding a lock // on cs_main because the CBlockIndex objects are dynamically allocated and // presumably never deleted. + if(!pindex) { + return; + } + LOCK(cs); pCurrentBlockIndex = pindex; nCachedBlockHeight = pCurrentBlockIndex->nHeight; diff --git a/src/init.cpp b/src/init.cpp index ee305fe80..c3c37fd4f 100644 --- a/src/init.cpp +++ b/src/init.cpp @@ -1883,6 +1883,7 @@ bool AppInit2(boost::thread_group& threadGroup, CScheduler& scheduler) darkSendPool.UpdatedBlockTip(chainActive.Tip()); mnpayments.UpdatedBlockTip(chainActive.Tip()); masternodeSync.UpdatedBlockTip(chainActive.Tip()); + governance.UpdatedBlockTip(chainActive.Tip()); // ********************************************************* Step 11d: start dash-privatesend thread