read_piece: handle failure to allocate piece buffer

This commit is contained in:
Steven Siloti 2017-08-28 19:57:58 -07:00 committed by Arvid Norberg
parent 41bfd41cea
commit 52ccad23b9
1 changed files with 6 additions and 0 deletions

View File

@ -1014,6 +1014,12 @@ namespace libtorrent
boost::shared_ptr<read_piece_struct> rp = boost::make_shared<read_piece_struct>();
rp->piece_data.reset(new (std::nothrow) char[piece_size]);
if (!rp->piece_data)
{
m_ses.alerts().emplace_alert<read_piece_alert>(
get_handle(), piece, error_code(boost::system::errc::not_enough_memory, generic_category()));
return;
}
rp->blocks_left = 0;
rp->fail = false;