Skip to content

Commit c2608e8

Browse files
authored
Merge pull request #140 from jcarpent/devel
Fix potential memory leak issue
2 parents 1740030 + 5ab1f16 commit c2608e8

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

include/eigenpy/details.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@
1616
#include "eigenpy/registration.hpp"
1717
#include "eigenpy/map.hpp"
1818

19+
namespace boost { namespace python { namespace detail {
20+
21+
template<class MatType>
22+
struct referent_size<Eigen::MatrixBase<MatType>&>
23+
{
24+
BOOST_STATIC_CONSTANT(
25+
std::size_t, value = sizeof(MatType));
26+
};
27+
28+
}}}
29+
1930
namespace boost { namespace python { namespace converter {
2031

2132
template<class MatType>
@@ -67,7 +78,8 @@ struct implicit<MatType,Eigen::MatrixBase<MatType> >
6778

6879
static void construct(PyObject* obj, rvalue_from_python_stage1_data* data)
6980
{
70-
void* storage = ((rvalue_from_python_storage<Source>*)data)->storage.bytes;
81+
void* storage = reinterpret_cast<rvalue_from_python_storage<Target>*>
82+
(reinterpret_cast<void*>(data))->storage.bytes;
7183

7284
arg_from_python<Source> get_source(obj);
7385
bool convertible = get_source.convertible();
@@ -565,8 +577,8 @@ namespace eigenpy
565577
PyArrayObject * pyArray = reinterpret_cast<PyArrayObject*>(pyObj);
566578
assert((PyArray_DIMS(pyArray)[0]<INT_MAX) && (PyArray_DIMS(pyArray)[1]<INT_MAX));
567579

568-
void* storage = ((bp::converter::rvalue_from_python_storage<MatType>*)
569-
((void*)memory))->storage.bytes;
580+
void* storage = reinterpret_cast<bp::converter::rvalue_from_python_storage<MatType>*>
581+
(reinterpret_cast<void*>(memory))->storage.bytes;
570582

571583
EigenObjectAllocator<MatType>::allocate(pyArray,storage);
572584

0 commit comments

Comments
 (0)