From 580534d39641508ffcd48a9bddb1f887791d68a3 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Sat, 10 Jun 2023 23:00:42 -0500 Subject: [PATCH] Protect against invalidated iterator in radar product manager --- scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp index 1d3d1126..dd7c8d35 100644 --- a/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp +++ b/scwx-qt/source/scwx/qt/manager/radar_product_manager.cpp @@ -1192,15 +1192,17 @@ void RadarProductManagerImpl::UpdateRecentRecords( std::shared_ptr record) { const std::size_t recentListMaxSize {cacheLimit_}; + bool iteratorErased = false; auto it = std::find(recentList.cbegin(), recentList.cend(), record); if (it != recentList.cbegin() && it != recentList.cend()) { // If the record exists beyond the front of the list, remove 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 recentList.push_front(record);