Skip to content
Snippets Groups Projects
Commit 8c62aebe authored by Andrews Sobral's avatar Andrews Sobral
Browse files

Fixed memory leak for OpenCV3 and Python3

parent e246604d
No related branches found
No related tags found
No related merge requests found
......@@ -106,6 +106,10 @@ struct Mat_PyObject_converter
using namespace boost::python;
typedef converter::rvalue_from_python_storage< T > storage_t;
// Object is a borrowed reference, so create a handle indicating it is
// borrowed for proper reference counting.
boost::python::handle<> handle(boost::python::borrowed(obj_ptr));
storage_t* the_storage = reinterpret_cast<storage_t*>( data );
void* memory_chunk = the_storage->storage.bytes;
......
......@@ -311,8 +311,11 @@ cv::Mat NDArrayConverter::toMat(const PyObject *o)
{
#if CV_MAJOR_VERSION == 3
m.addref();
Py_INCREF(o);
// Not needed anymore, the pointer is now managed by a borrowed handle, which
// which will handle reference counting.
// Py_INCREF(o);
#else
// TODO: I assume this one is leaking too, but don't have CV v2 to test.
m.refcount = refcountFromPyObject(o);
m.addref(); // protect the original numpy array from deallocation
// (since Mat destructor will decrement the reference counter)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment