Skip to content

Commit eaab435

Browse files
committed
Fix leak in webp_encode
* Free the output buffer on webp encode error
1 parent 84b88a9 commit eaab435

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/_webp.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,10 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
641641
ImagingSectionLeave(&cookie);
642642

643643
WebPPictureFree(&pic);
644+
645+
output = writer.mem;
646+
ret_size = writer.size;
647+
644648
if (!ok) {
645649
int error_code = (&pic)->error_code;
646650
char message[50] = "";
@@ -652,10 +656,9 @@ WebPEncode_wrapper(PyObject *self, PyObject *args) {
652656
);
653657
}
654658
PyErr_Format(PyExc_ValueError, "encoding error %d%s", error_code, message);
659+
free(output);
655660
return NULL;
656661
}
657-
output = writer.mem;
658-
ret_size = writer.size;
659662

660663
{
661664
/* I want to truncate the *_size items that get passed into WebP

0 commit comments

Comments
 (0)