From 0fff5f9e4db3b3f04ac1159e42221cf9f2217170 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Thu, 13 Mar 2025 11:21:28 -0400 Subject: [PATCH 1/3] Fix boost::containers::stable_vector memory leak in MapWidget --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 9096a4b7..ffedbcc7 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1185,6 +1185,8 @@ void MapWidgetImpl::AddLayers() layerList_.clear(); genericLayers_.clear(); placefileLayers_.clear(); + customLayers_.clear(); + customLayers_.shrink_to_fit(); // Update custom layer list from model customLayers_ = model::LayerModel::Instance()->GetLayers(); From 61ac1e56124d31342ead7edb9072cc0bd76200f2 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 14 Mar 2025 12:25:18 -0400 Subject: [PATCH 2/3] Fix boost::containers::stable_vector memory leak in MapWidget by local variable --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index ffedbcc7..51aa98ef 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -204,8 +205,7 @@ public: const std::vector emptyStyles_ {}; std::vector customStyles_ { MapStyle {.name_ {"Custom"}, .url_ {}, .drawBelow_ {}}}; - QStringList styleLayers_; - types::LayerVector customLayers_; + QStringList styleLayers_; boost::uuids::uuid customStyleUrlChangedCallbackId_ {}; boost::uuids::uuid customStyleDrawBelowChangedCallbackId_ {}; @@ -1185,22 +1185,20 @@ void MapWidgetImpl::AddLayers() layerList_.clear(); genericLayers_.clear(); placefileLayers_.clear(); - customLayers_.clear(); - customLayers_.shrink_to_fit(); // Update custom layer list from model - customLayers_ = model::LayerModel::Instance()->GetLayers(); + types::LayerVector customLayers = model::LayerModel::Instance()->GetLayers(); // Start by drawing layers before any style-defined layers std::string before = styleLayers_.front().toStdString(); // Loop through each custom layer in reverse order - for (auto it = customLayers_.crbegin(); it != customLayers_.crend(); ++it) + for (const auto & customLayer : std::ranges::reverse_view(customLayers)) { - if (it->type_ == types::LayerType::Map) + if (customLayer.type_ == types::LayerType::Map) { // Style-defined map layers - switch (std::get(it->description_)) + switch (std::get(customLayer.description_)) { // Subsequent layers are drawn underneath the map symbology layer case types::MapLayer::MapUnderlay: @@ -1216,10 +1214,10 @@ void MapWidgetImpl::AddLayers() break; } } - else if (it->displayed_[id_]) + else if (customLayer.displayed_[id_]) { // If the layer is displayed for the current map, add it - AddLayer(it->type_, it->description_, before); + AddLayer(customLayer.type_, customLayer.description_, before); } } } From 3ef794a25e4661a828722ab2e098402f062e1530 Mon Sep 17 00:00:00 2001 From: AdenKoperczak Date: Fri, 14 Mar 2025 12:31:37 -0400 Subject: [PATCH 3/3] Clang tidy/format fixes for fix_stable_vector_memory_leak --- scwx-qt/source/scwx/qt/map/map_widget.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/scwx-qt/source/scwx/qt/map/map_widget.cpp b/scwx-qt/source/scwx/qt/map/map_widget.cpp index 51aa98ef..466a03fe 100644 --- a/scwx-qt/source/scwx/qt/map/map_widget.cpp +++ b/scwx-qt/source/scwx/qt/map/map_widget.cpp @@ -1193,7 +1193,7 @@ void MapWidgetImpl::AddLayers() std::string before = styleLayers_.front().toStdString(); // Loop through each custom layer in reverse order - for (const auto & customLayer : std::ranges::reverse_view(customLayers)) + for (const auto& customLayer : std::ranges::reverse_view(customLayers)) { if (customLayer.type_ == types::LayerType::Map) { @@ -1214,6 +1214,8 @@ void MapWidgetImpl::AddLayers() break; } } + // id_ is always < 4, so this is safe + // NOLINTNEXTLINE(cppcoreguidelines-pro-bounds-constant-array-index) else if (customLayer.displayed_[id_]) { // If the layer is displayed for the current map, add it