fixed issue where pop_alerts() could return old, invalid alerts

This commit is contained in:
arvidn
2020-07-10 16:56:20 +02:00
committed by Arvid Norberg
parent f4defa52b2
commit 82521eb1ae
4 changed files with 32 additions and 1 deletions

View File

@ -1,3 +1,4 @@
* fixed issue where pop_alerts() could return old, invalid alerts
* fix issue when receiving have-all message before the metadata
* don't leave lingering part files handles open
* disallow calling add_piece() during checking

View File

@ -106,7 +106,11 @@ namespace libtorrent {
{
std::lock_guard<std::recursive_mutex> lock(m_mutex);
if (m_alerts[m_generation].empty()) return;
if (m_alerts[m_generation].empty())
{
alerts.clear();
return;
}
if (m_dropped.any()) {
emplace_alert<alerts_dropped_alert>(m_dropped);

View File

@ -281,6 +281,16 @@ TORRENT_TEST(alert_mask)
TEST_CHECK(!mgr.should_post<torrent_paused_alert>());
}
TORRENT_TEST(get_all_empty)
{
alert_manager mgr(100, alert_category::all);
std::vector<alert*> alerts(10);
mgr.get_all(alerts);
TEST_CHECK(alerts.empty());
}
TORRENT_TEST(dropped_alerts)
{
alert_manager mgr(1, alert_category::all);

View File

@ -424,6 +424,22 @@ TORRENT_TEST(save_state_peer_id)
TEST_EQUAL(ses.get_settings().get_str(settings_pack::peer_fingerprint), "foobar");
}
TORRENT_TEST(pop_alert_clear)
{
session s;
// make sure the vector is cleared if there are no alerts to be popped
std::vector<alert*> alerts(100);
for (int i = 0; i < 10; ++i)
{
alerts.resize(100);
s.pop_alerts(&alerts);
if (alerts.empty()) break;
}
TEST_CHECK(alerts.empty());
}
#if !defined TORRENT_DISABLE_LOGGING
#if !defined TORRENT_DISABLE_DHT