From 3e7e4c8c527efb636d4b9654f748cd947d17fa92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matthias=20M=C3=B6ller?= Date: Thu, 29 Aug 2024 11:21:59 +0200 Subject: [PATCH] Fix potential memory leak in SceneCombiner for LWS/IRR/MD3 loader (#5721) * fix potential memory leak in scenecombiner * also cleansup srclist * de-duplicates before deleting --------- Co-authored-by: Kim Kulling --- code/Common/SceneCombiner.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/code/Common/SceneCombiner.cpp b/code/Common/SceneCombiner.cpp index 09215d055..88fa49793 100644 --- a/code/Common/SceneCombiner.cpp +++ b/code/Common/SceneCombiner.cpp @@ -63,6 +63,7 @@ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include namespace Assimp { @@ -252,6 +253,14 @@ void SceneCombiner::AttachToGraph(aiScene *master, std::vector &srcList, unsigned int flags) { if (nullptr == _dest) { + std::unordered_set uniqueScenes; + uniqueScenes.insert(master); + for (const auto &item : srcList) { + uniqueScenes.insert(item.scene); + } + for (const auto &item : uniqueScenes) { + delete item; + } return; } @@ -259,6 +268,7 @@ void SceneCombiner::MergeScenes(aiScene **_dest, aiScene *master, std::vector