Skip to content

Commit

Permalink
binding: Fix memory leak in buildGeomFromUrdf and buildGeomFromUrdfSt…
Browse files Browse the repository at this point in the history
…ring
  • Loading branch information
jorisv committed Nov 9, 2023
1 parent be55be6 commit efa74c4
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion bindings/python/parsers/urdf/geometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,20 @@ namespace pinocchio
template <class ArgumentPackage>
static PyObject* postcall(ArgumentPackage const& args_, PyObject* result)
{
// If owner_arg exist, we run bp::return_internal_reference postcall
// result lifetime will be tied to owner_arg lifetime
PyObject* patient = bp::detail::get_prev<owner_arg>::execute(args_, result);
if (patient != Py_None)
return bp::return_internal_reference<owner_arg>::postcall(args_, result);
return result;
// If owner_arg doesn't exist, then Python will have to manage the result lifetime
bp::extract<GeometryModel*> geom_model_extract(result);
if (geom_model_extract.check())
{
return bp::to_python_indirect<GeometryModel, bp::detail::make_owning_holder>()(geom_model_extract());
}
// If returned value is not a GeometryModel*, then raise an error
PyErr_SetString(PyExc_RuntimeError, "pinocchio::python::return_value_policy only work on GeometryModel* data type");
return 0;
}
};

Expand Down

0 comments on commit efa74c4

Please sign in to comment.