From 731a9f6ceaf061a7630b4d859515bf3f2ebe3892 Mon Sep 17 00:00:00 2001 From: Jason Rhinelander Date: Tue, 16 May 2017 09:38:58 -0400 Subject: [PATCH] Fix Py_buffer leak on GetBuffer failure Fixes #852. --- include/pybind11/pytypes.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) 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); } };