From 9c5d7578796c5cb3aa9554f329cc281d8340ad6c Mon Sep 17 00:00:00 2001 From: erwincoumans Date: Thu, 12 Apr 2018 12:43:29 -0700 Subject: [PATCH] PyBullet: fix memory leak in setJointMotorControlArray Fixes issue #1633 --- examples/pybullet/pybullet.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/examples/pybullet/pybullet.c b/examples/pybullet/pybullet.c index 2c86daef8..31cdc20eb 100644 --- a/examples/pybullet/pybullet.c +++ b/examples/pybullet/pybullet.c @@ -1909,6 +1909,7 @@ static PyObject* pybullet_setJointMotorControlArray(PyObject* self, PyObject* ar { Py_DECREF(kpsSeq); } + PyErr_SetString(SpamError, "number of kds should match the number of joint indices"); return NULL; } @@ -1993,6 +1994,29 @@ static PyObject* pybullet_setJointMotorControlArray(PyObject* self, PyObject* ar statusHandle = b3SubmitClientCommandAndWaitStatus(sm, commandHandle); + + if (targetVelocitiesSeq) + { + Py_DECREF(targetVelocitiesSeq); + } + if (targetPositionsSeq) + { + Py_DECREF(targetPositionsSeq); + } + if (forcesSeq) + { + Py_DECREF(forcesSeq); + } + if (kpsSeq) + { + Py_DECREF(kpsSeq); + } + + if (kdsSeq) + { + Py_DECREF(kdsSeq); + } + Py_DECREF(jointIndicesSeq); Py_INCREF(Py_None); return Py_None;