From 70950692eb595df3d06d2ef91820566a5041fb35 Mon Sep 17 00:00:00 2001 From: wmayer Date: Thu, 25 Apr 2024 14:50:59 +0200 Subject: [PATCH] Material: Fix two direct memory leaks in ModelLoader::addToTree and ModelLoader::loadLibrary --- src/Mod/Material/App/ModelLoader.cpp | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Mod/Material/App/ModelLoader.cpp b/src/Mod/Material/App/ModelLoader.cpp index 595c3f0d85..ef816e6b9c 100644 --- a/src/Mod/Material/App/ModelLoader.cpp +++ b/src/Mod/Material/App/ModelLoader.cpp @@ -235,7 +235,7 @@ void ModelLoader::addToTree(std::shared_ptr model, Model::ModelType type = (base == "Model") ? Model::ModelType_Physical : Model::ModelType_Appearance; - Model* finalModel = new Model(library, type, name, directory, uuid, description, url, doi); + Model finalModel(library, type, name, directory, uuid, description, url, doi); // Add inheritance list if (yamlModel[base]["Inherits"]) { @@ -243,7 +243,7 @@ void ModelLoader::addToTree(std::shared_ptr model, for (auto it = inherits.begin(); it != inherits.end(); it++) { QString nodeName = QString::fromStdString((*it)["UUID"].as()); - finalModel->addInheritance(nodeName); + finalModel.addInheritance(nodeName); } } @@ -299,11 +299,11 @@ void ModelLoader::addToTree(std::shared_ptr model, property.setInheritance((*inheritances)[key]); } - finalModel->addProperty(property); + finalModel.addProperty(property); } } - (*_modelMap)[uuid] = library->addModel(*finalModel, directory); + (*_modelMap)[uuid] = library->addModel(finalModel, directory); } void ModelLoader::loadLibrary(std::shared_ptr library) @@ -330,16 +330,14 @@ void ModelLoader::loadLibrary(std::shared_ptr library) } } - std::map, QString>* inheritances = - new std::map, QString>(); + std::map, QString> inheritances; for (auto it = _modelEntryMap->begin(); it != _modelEntryMap->end(); it++) { - dereference(it->second, inheritances); + dereference(it->second, &inheritances); } for (auto it = _modelEntryMap->begin(); it != _modelEntryMap->end(); it++) { - addToTree(it->second, inheritances); + addToTree(it->second, &inheritances); } - // delete inheritances; } void ModelLoader::loadLibraries()