Skip to content

Commit

Permalink
Fix addrman crashes
Browse files Browse the repository at this point in the history
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: bitcoin#1065, bitcoin#1156
  • Loading branch information
sipa committed May 5, 2012
1 parent 29a86a1 commit 56f1e91
Showing 1 changed file with 5 additions and 2 deletions.
7 changes: 5 additions & 2 deletions src/addrman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,18 +130,21 @@ 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;
assert(nOldest == -1 || mapInfo.count(nTemp) == 1);
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)
Expand Down

0 comments on commit 56f1e91

Please sign in to comment.