Skip to content

Commit 5e4b6e9

Browse files
authored
Merge pull request #4381 from radarhere/memory
Release buffer if function returns prematurely
2 parents 291f1eb + e7ce609 commit 5e4b6e9

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/map.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -354,17 +354,21 @@ PyImaging_MapBuffer(PyObject* self, PyObject* args)
354354

355355
if (view.len < 0) {
356356
PyErr_SetString(PyExc_ValueError, "buffer has negative size");
357+
PyBuffer_Release(&view);
357358
return NULL;
358359
}
359360
if (offset + size > view.len) {
360361
PyErr_SetString(PyExc_ValueError, "buffer is not large enough");
362+
PyBuffer_Release(&view);
361363
return NULL;
362364
}
363365

364366
im = ImagingNewPrologueSubtype(
365367
mode, xsize, ysize, sizeof(ImagingBufferInstance));
366-
if (!im)
368+
if (!im) {
369+
PyBuffer_Release(&view);
367370
return NULL;
371+
}
368372

369373
/* setup file pointers */
370374
if (ystep > 0)

0 commit comments

Comments
 (0)