Avoid invalid iterator comparison after objects mutex is unlocked

This commit is contained in:
Dan Paulat 2024-11-15 05:40:34 -06:00
parent 845d5b5707
commit f7949cc404

View file

@ -183,6 +183,7 @@ AwsNexradDataProvider::GetTimePointsByDate(
std::shared_lock lock(p->objectsMutex_); std::shared_lock lock(p->objectsMutex_);
// Is the date present in the date list? // Is the date present in the date list?
bool currentDatePresent;
auto currentDateIterator = auto currentDateIterator =
std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day); std::find(p->objectDates_.cbegin(), p->objectDates_.cend(), day);
if (currentDateIterator == p->objectDates_.cend()) if (currentDateIterator == p->objectDates_.cend())
@ -199,6 +200,12 @@ AwsNexradDataProvider::GetTimePointsByDate(
// Re-lock mutex // Re-lock mutex
lock.lock(); lock.lock();
currentDatePresent = false;
}
else
{
currentDatePresent = true;
} }
// Determine objects to retrieve // Determine objects to retrieve
@ -216,7 +223,7 @@ AwsNexradDataProvider::GetTimePointsByDate(
// If we haven't updated the most recently queried dates yet, because the // If we haven't updated the most recently queried dates yet, because the
// date was already cached, update // date was already cached, update
if (currentDateIterator != p->objectDates_.cend()) if (currentDatePresent)
{ {
p->UpdateObjectDates(date); p->UpdateObjectDates(date);
} }