mirror of
https://github.com/python-pillow/Pillow.git
synced 2025-07-15 10:42:19 +03:00
webp: fix memory leak
The "S" format specifier for Py_BuildValue *increases* the object reference count.
This commit is contained in:
parent
3d5dd3b4fc
commit
4930b66aa9
23
_webp.c
23
_webp.c
|
@ -138,7 +138,7 @@ PyObject* WebPDecode_wrapper(PyObject* self, PyObject* args)
|
||||||
PyBytesObject *webp_string;
|
PyBytesObject *webp_string;
|
||||||
const uint8_t *webp;
|
const uint8_t *webp;
|
||||||
Py_ssize_t size;
|
Py_ssize_t size;
|
||||||
PyObject *ret, *bytes, *pymode, *icc_profile = Py_None, *exif = Py_None;
|
PyObject *ret = Py_None, *bytes = NULL, *pymode = NULL, *icc_profile = NULL, *exif = NULL;
|
||||||
WebPDecoderConfig config;
|
WebPDecoderConfig config;
|
||||||
VP8StatusCode vp8_status_code = VP8_STATUS_OK;
|
VP8StatusCode vp8_status_code = VP8_STATUS_OK;
|
||||||
char* mode = "RGB";
|
char* mode = "RGB";
|
||||||
|
@ -194,10 +194,8 @@ PyObject* WebPDecode_wrapper(PyObject* self, PyObject* args)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vp8_status_code != VP8_STATUS_OK) {
|
if (vp8_status_code != VP8_STATUS_OK)
|
||||||
WebPFreeDecBuffer(&config.output);
|
goto end;
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (config.output.colorspace < MODE_YUV) {
|
if (config.output.colorspace < MODE_YUV) {
|
||||||
bytes = PyBytes_FromStringAndSize((char *)config.output.u.RGBA.rgba,
|
bytes = PyBytes_FromStringAndSize((char *)config.output.u.RGBA.rgba,
|
||||||
|
@ -215,8 +213,21 @@ PyObject* WebPDecode_wrapper(PyObject* self, PyObject* args)
|
||||||
pymode = PyString_FromString(mode);
|
pymode = PyString_FromString(mode);
|
||||||
#endif
|
#endif
|
||||||
ret = Py_BuildValue("SiiSSS", bytes, config.output.width,
|
ret = Py_BuildValue("SiiSSS", bytes, config.output.width,
|
||||||
config.output.height, pymode, icc_profile, exif);
|
config.output.height, pymode,
|
||||||
|
NULL == icc_profile ? Py_None : icc_profile,
|
||||||
|
NULL == exif ? Py_None : exif);
|
||||||
|
|
||||||
|
end:
|
||||||
WebPFreeDecBuffer(&config.output);
|
WebPFreeDecBuffer(&config.output);
|
||||||
|
|
||||||
|
Py_XDECREF(bytes);
|
||||||
|
Py_XDECREF(pymode);
|
||||||
|
Py_XDECREF(icc_profile);
|
||||||
|
Py_XDECREF(exif);
|
||||||
|
|
||||||
|
if (Py_None == ret)
|
||||||
|
Py_RETURN_NONE;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user