From e7ce609889c3722a86811ef5a604c1ee0d8767f6 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 25 Jan 2020 23:22:03 +1100 Subject: [PATCH] Release buffer if function returns prematurely --- src/map.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/map.c b/src/map.c index a8fb69c6e..b887e57f3 100644 --- a/src/map.c +++ b/src/map.c @@ -355,17 +355,21 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args) if (view.len < 0) { PyErr_SetString(PyExc_ValueError, "buffer has negative size"); + PyBuffer_Release(&view); return NULL; } if (offset + size > view.len) { PyErr_SetString(PyExc_ValueError, "buffer is not large enough"); + PyBuffer_Release(&view); return NULL; } im = ImagingNewPrologueSubtype( mode, xsize, ysize, sizeof(ImagingBufferInstance)); - if (!im) + if (!im) { + PyBuffer_Release(&view); return NULL; + } /* setup file pointers */ if (ystep > 0)