@@ -146,6 +146,7 @@ static PyObject *fkine_all(PyObject *self, PyObject *args)
146146 }
147147 }
148148
149+ Py_DECREF (iter_links );
149150 free (ret );
150151
151152 Py_RETURN_NONE ;
@@ -328,6 +329,11 @@ static PyObject *link_init(PyObject *self, PyObject *args)
328329 link -> op = tz ;
329330 }
330331
332+ Py_DECREF (iter_base );
333+ Py_DECREF (iter_wT );
334+ Py_DECREF (iter_sT );
335+ Py_DECREF (iter_sq );
336+
331337 ret = PyCapsule_New (link , "Link" , NULL );
332338 return ret ;
333339}
@@ -380,6 +386,20 @@ static PyObject *link_update(PyObject *self, PyObject *args)
380386 iter_sT = PyObject_GetIter (py_shape_sT );
381387 iter_sq = PyObject_GetIter (py_shape_sq );
382388
389+ if (link -> shape_base != 0 )
390+ free (link -> shape_base );
391+ if (link -> shape_wT != 0 )
392+ free (link -> shape_wT );
393+ if (link -> shape_sT != 0 )
394+ free (link -> shape_sT );
395+ if (link -> shape_sq != 0 )
396+ free (link -> shape_sq );
397+
398+ link -> shape_base = 0 ;
399+ link -> shape_wT = 0 ;
400+ link -> shape_sT = 0 ;
401+ link -> shape_sq = 0 ;
402+
383403 link -> shape_base = (npy_float64 * * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
384404 link -> shape_wT = (npy_float64 * * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
385405 link -> shape_sT = (npy_float64 * * )PyMem_RawCalloc (n_shapes , sizeof (npy_float64 ));
@@ -434,6 +454,11 @@ static PyObject *link_update(PyObject *self, PyObject *args)
434454 link -> parent = parent ;
435455 link -> n_shapes = n_shapes ;
436456
457+ Py_DECREF (iter_base );
458+ Py_DECREF (iter_wT );
459+ Py_DECREF (iter_sT );
460+ Py_DECREF (iter_sq );
461+
437462 Py_RETURN_NONE ;
438463}
439464
@@ -594,6 +619,8 @@ void _jacobe(PyObject *links, int m, int n, npy_float64 *q, npy_float64 *etool,
594619 }
595620 PyList_Reverse (links );
596621
622+ Py_DECREF (iter_links );
623+
597624 free (T );
598625 free (U );
599626 free (temp );
@@ -701,6 +728,8 @@ void _jacob0(PyObject *links, int m, int n, npy_float64 *q, npy_float64 *etool,
701728 }
702729 }
703730
731+ Py_DECREF (iter_links );
732+
704733 free (T );
705734 free (U );
706735 free (temp );
@@ -739,6 +768,8 @@ void _fkine(PyObject *links, int n, npy_float64 *q, npy_float64 *etool, npy_floa
739768 copy (ret , current );
740769 mult (current , tool , ret );
741770
771+ Py_DECREF (iter_links );
772+
742773 free (temp );
743774 free (current );
744775}
0 commit comments