diff --git a/src/_imaging.c b/src/_imaging.c index e7afc4ed955..0b455a96c5b 100644 --- a/src/_imaging.c +++ b/src/_imaging.c @@ -842,7 +842,9 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) { } } } - PyBuffer_Release(&buffer_info); + if (!table_data) { + PyBuffer_Release(&buffer_info); + } } } @@ -859,6 +861,8 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) { if (!prepared) { if (free_table_data) { free(table_data); + } else { + PyBuffer_Release(&buffer_info); } return (INT16 *)ImagingError_MemoryError(); } @@ -901,6 +905,8 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) { #undef PRECISION_BITS if (free_table_data) { free(table_data); + } else { + PyBuffer_Release(&buffer_info); } return prepared; }