reserve space in torrent lists up-front, to make transitioning list membership unable to fail

This commit is contained in:
arvidn 2017-12-27 12:17:45 +01:00 committed by Arvid Norberg
parent 55fbfb8b7f
commit ab9fcdf029
1 changed files with 9 additions and 0 deletions

View File

@ -4955,6 +4955,15 @@ namespace {
return std::make_pair(ptr_t(), false);
}
// make sure we have enough memory in the torrent lists up-front,
// since when torrents changes states, we cannot allocate memory that
// might fail.
size_t const num_torrents = m_torrents.size();
for (auto& l : m_torrent_lists)
{
l.reserve(num_torrents + 1);
}
torrent_ptr = std::make_shared<torrent>(*this
, 16 * 1024, m_paused
, params);