Imath
Imath copied to clipboard
V3fArrayFromBuffer Memory Leak
Hi
There's a memory leak in imath.V3fArrayFromBuffer
and related functions, caused by creating a PyBuffer
with PyObject_GetBuffer
, but not releasing it on all paths with PyBuffer_Release
. It can be solved like this:
diff --git a/src/python/PyImath/PyImathBufferProtocol.cpp b/src/python/PyImath/PyImathBufferProtocol.cpp
index 75e7006..a579b55 100644
--- a/src/python/PyImath/PyImathBufferProtocol.cpp
+++ b/src/python/PyImath/PyImathBufferProtocol.cpp
@@ -361,6 +361,7 @@ fixedArrayFromBuffer (PyObject *obj)
ArrayT *array = new ArrayT (view.shape[0], PyImath::UNINITIALIZED);
memcpy (&array->direct_index(0), view.buf, view.len);
+ PyBuffer_Release(&view);
return array;
}