aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main.cpp26
-rw-r--r--src/net.cpp17
2 files changed, 41 insertions, 2 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 22baf0f3eb..bde7b5acdb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -4750,3 +4750,29 @@ uint64 CTxOutCompressor::DecompressAmount(uint64 x)
}
return n;
}
+
+
+class CMainCleanup
+{
+public:
+ CMainCleanup() {}
+ ~CMainCleanup() {
+ // block headers
+ std::map<uint256, CBlockIndex*>::iterator it1 = mapBlockIndex.begin();
+ for (; it1 != mapBlockIndex.end(); it1++)
+ delete (*it1).second;
+ mapBlockIndex.clear();
+
+ // orphan blocks
+ std::map<uint256, CBlock*>::iterator it2 = mapOrphanBlocks.begin();
+ for (; it2 != mapOrphanBlocks.end(); it2++)
+ delete (*it2).second;
+ mapOrphanBlocks.clear();
+
+ // orphan transactions
+ std::map<uint256, CDataStream*>::iterator it3 = mapOrphanTransactions.begin();
+ for (; it3 != mapOrphanTransactions.end(); it3++)
+ delete (*it3).second;
+ mapOrphanTransactions.clear();
+ }
+} instance_of_cmaincleanup;
diff --git a/src/net.cpp b/src/net.cpp
index 3406a28b0e..ed2e662fd8 100644
--- a/src/net.cpp
+++ b/src/net.cpp
@@ -660,12 +660,12 @@ void ThreadSocketHandler(void* parg)
printf("ThreadSocketHandler exited\n");
}
+static list<CNode*> vNodesDisconnected;
+
void ThreadSocketHandler2(void* parg)
{
printf("ThreadSocketHandler started\n");
- list<CNode*> vNodesDisconnected;
unsigned int nPrevNodeCount = 0;
-
loop
{
//
@@ -1992,6 +1992,7 @@ bool StopNode()
Sleep(20);
Sleep(50);
DumpAddresses();
+
return true;
}
@@ -2012,6 +2013,18 @@ public:
if (closesocket(hListenSocket) == SOCKET_ERROR)
printf("closesocket(hListenSocket) failed with error %d\n", WSAGetLastError());
+ // clean up some globals (to help leak detection)
+ BOOST_FOREACH(CNode *pnode, vNodes)
+ delete pnode;
+ BOOST_FOREACH(CNode *pnode, vNodesDisconnected)
+ delete pnode;
+ vNodes.clear();
+ vNodesDisconnected.clear();
+ delete semOutbound;
+ semOutbound = NULL;
+ delete pnodeLocalHost;
+ pnodeLocalHost = NULL;
+
#ifdef WIN32
// Shutdown Windows Sockets
WSACleanup();