mirror of
https://github.com/ciphervance/supercell-wx.git
synced 2025-10-30 20:00:05 +00:00
Protect against invalidated iterator in radar product manager
This commit is contained in:
parent
ca61ed257d
commit
580534d396
1 changed files with 3 additions and 1 deletions
|
|
@ -1192,15 +1192,17 @@ void RadarProductManagerImpl::UpdateRecentRecords(
|
||||||
std::shared_ptr<types::RadarProductRecord> record)
|
std::shared_ptr<types::RadarProductRecord> record)
|
||||||
{
|
{
|
||||||
const std::size_t recentListMaxSize {cacheLimit_};
|
const std::size_t recentListMaxSize {cacheLimit_};
|
||||||
|
bool iteratorErased = false;
|
||||||
|
|
||||||
auto it = std::find(recentList.cbegin(), recentList.cend(), record);
|
auto it = std::find(recentList.cbegin(), recentList.cend(), record);
|
||||||
if (it != recentList.cbegin() && it != recentList.cend())
|
if (it != recentList.cbegin() && it != recentList.cend())
|
||||||
{
|
{
|
||||||
// If the record exists beyond the front of the list, remove it
|
// If the record exists beyond the front of the list, remove it
|
||||||
recentList.erase(it);
|
recentList.erase(it);
|
||||||
|
iteratorErased = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (recentList.size() == 0 || it != recentList.cbegin())
|
if (iteratorErased || recentList.size() == 0 || it != recentList.cbegin())
|
||||||
{
|
{
|
||||||
// Add the record to the front of the list, unless it's already there
|
// Add the record to the front of the list, unless it's already there
|
||||||
recentList.push_front(record);
|
recentList.push_front(record);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue