Skip to content

Commit

Permalink
Merge pull request #4381 from radarhere/memory
Browse files Browse the repository at this point in the history
Release buffer if function returns prematurely
  • Loading branch information
hugovk committed Mar 25, 2020
2 parents 291f1eb + e7ce609 commit 5e4b6e9
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/map.c
Expand Up @@ -354,17 +354,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)
Expand Down

0 comments on commit 5e4b6e9

Please sign in to comment.