diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index 8093eada..8a8499c1 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -1155,8 +1155,10 @@ public: 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); } };