From: Pieter Wuille Date: Sat, 5 May 2012 19:22:55 +0000 (+0200) Subject: Fix addrman crashes X-Git-Tag: v0.4.0-unstable~129^2~1^2^2~16 X-Git-Url: https://git.novaco.in/?a=commitdiff_plain;h=adecb2ea00c8e8944a8c9bc5bc10e84ed1a568c0;hp=b94e6eb5a510315c4713ffc8bcfbfceb674691dc;p=novacoin.git Fix addrman crashes A function returned the element to remove from a bucket, instead of its position in that bucket. This function was only called when a tried bucket overflowed, which only happens after many outgoing connections have been made. Closes: #1065, #1156 --- diff --git a/src/addrman.cpp b/src/addrman.cpp index 11dd2a7..9edbcc3 100644 --- a/src/addrman.cpp +++ b/src/addrman.cpp @@ -124,17 +124,20 @@ int CAddrMan::SelectTried(int nKBucket) // random shuffle the first few elements (using the entire list) // find the least recently tried among them int64 nOldest = -1; + int nOldestPos = -1; for (unsigned int i = 0; i < ADDRMAN_TRIED_ENTRIES_INSPECT_ON_EVICT && i < vTried.size(); i++) { int nPos = GetRandInt(vTried.size() - i) + i; int nTemp = vTried[nPos]; vTried[nPos] = vTried[i]; vTried[i] = nTemp; - if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess) + if (nOldest == -1 || mapInfo[nTemp].nLastSuccess < mapInfo[nOldest].nLastSuccess) { nOldest = nTemp; + nOldestPos = nPos; + } } - return nOldest; + return nOldestPos; } int CAddrMan::ShrinkNew(int nUBucket)