Fix Py_buffer leak on GetBuffer failure
Fixes #852.
diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h
index 8093ead..8a8499c 100644
--- a/include/pybind11/pytypes.h
+++ b/include/pybind11/pytypes.h
@@ -1155,8 +1155,10 @@
int flags = PyBUF_STRIDES | PyBUF_FORMAT;
if (writable) flags |= PyBUF_WRITABLE;
Py_buffer *view = new Py_buffer();
- if (PyObject_GetBuffer(m_ptr, view, flags) != 0)
+ if (PyObject_GetBuffer(m_ptr, view, flags) != 0) {
+ delete view;
throw error_already_set();
+ }
return buffer_info(view);
}
};