Skip to content

Commit 270dc69

Browse files
authored
Do not release Py_buffer until buf is no longer in use (#9683)
1 parent 5beb446 commit 270dc69

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/_imaging.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -842,7 +842,9 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) {
842842
}
843843
}
844844
}
845-
PyBuffer_Release(&buffer_info);
845+
if (!table_data) {
846+
PyBuffer_Release(&buffer_info);
847+
}
846848
}
847849
}
848850

@@ -859,6 +861,8 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) {
859861
if (!prepared) {
860862
if (free_table_data) {
861863
free(table_data);
864+
} else {
865+
PyBuffer_Release(&buffer_info);
862866
}
863867
return (INT16 *)ImagingError_MemoryError();
864868
}
@@ -901,6 +905,8 @@ _prepare_lut_table(PyObject *table, Py_ssize_t table_size) {
901905
#undef PRECISION_BITS
902906
if (free_table_data) {
903907
free(table_data);
908+
} else {
909+
PyBuffer_Release(&buffer_info);
904910
}
905911
return prepared;
906912
}

0 commit comments

Comments
 (0)