From b1cbc3d4b0cf317cd48481114fba862ebf625465 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 30 Mar 2017 13:30:38 -0700 Subject: [PATCH 1/4] 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; } From a7c67b4d9d2fe34a1264ac22d8888df773a6bd50 Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 30 Mar 2017 13:50:02 -0700 Subject: [PATCH 2/4] avoid memory leaks, even if a the python interpreter exits without calling 'disconnect' on all physics servers (register a Py_AtExit function that cleans all up), to avoid memory leaks --- examples/pybullet/pybullet.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index cc9bda8d0..85416fbfa 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -1,3 +1,4 @@ +#include "vld.h" #include "../SharedMemory/PhysicsClientC_API.h" #include "../SharedMemory/PhysicsDirectC_API.h" #include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h" @@ -398,6 +399,22 @@ static PyObject* pybullet_disconnectPhysicsServer(PyObject* self, return Py_None; } + +void b3pybulletExitFunc() +{ + int i; + for (i=0;i Date: Thu, 30 Mar 2017 13:54:32 -0700 Subject: [PATCH 3/4] avoid checking beyond string length in b3CommandLineArgs.h --- src/Bullet3Common/b3CommandLineArgs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Bullet3Common/b3CommandLineArgs.h b/src/Bullet3Common/b3CommandLineArgs.h index 481f95aaf..38df8e260 100644 --- a/src/Bullet3Common/b3CommandLineArgs.h +++ b/src/Bullet3Common/b3CommandLineArgs.h @@ -29,7 +29,7 @@ public: { std::string arg = argv[i]; - if ((arg[0] != '-') || (arg[1] != '-')) { + if ((arg.length() < 2) || (arg[0] != '-') || (arg[1] != '-')) { continue; } From 473196a492d4b5c4d4d94729759dac335a06bf2c Mon Sep 17 00:00:00 2001 From: Erwin Coumans Date: Thu, 30 Mar 2017 13:56:37 -0700 Subject: [PATCH 4/4] remove vld.h --- examples/pybullet/pybullet.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 85416fbfa..b041f88d8 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -1,4 +1,4 @@ -#include "vld.h" + #include "../SharedMemory/PhysicsClientC_API.h" #include "../SharedMemory/PhysicsDirectC_API.h" #include "../SharedMemory/SharedMemoryInProcessPhysicsC_API.h"