From b1cbc3d4b0cf317cd48481114fba862ebf625465 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 30 Mar 2017 13:30:38 -0700 Subject: [PATCH] fix a potential memory leak for URDF files with multiple materials using the same name --- examples/Importers/ImportURDFDemo/UrdfParser.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/examples/Importers/ImportURDFDemo/UrdfParser.cpp b/examples/Importers/ImportURDFDemo/UrdfParser.cpp index 2ec443db2..cf5b9c626 100644 --- a/examples/Importers/ImportURDFDemo/UrdfParser.cpp +++ b/examples/Importers/ImportURDFDemo/UrdfParser.cpp @@ -620,6 +620,15 @@ bool UrdfParser::parseVisual(UrdfModel& model, UrdfVisual& visual, TiXmlElement* if (parseMaterial(visual.m_geometry.m_localMaterial, mat,logger)) { UrdfMaterial* matPtr = new UrdfMaterial(visual.m_geometry.m_localMaterial); + + UrdfMaterial** oldMatPtrPtr = model.m_materials[matPtr->m_name.c_str()]; + if (oldMatPtrPtr) + { + UrdfMaterial* oldMatPtr = *oldMatPtrPtr; + model.m_materials.remove(matPtr->m_name.c_str()); + if (oldMatPtr) + delete oldMatPtr; + } model.m_materials.insert(matPtr->m_name.c_str(),matPtr); visual.m_geometry.m_hasLocalMaterial = true; }