mirror of
https://gitlab.com/libvirt/libvirt-python.git
synced 2025-12-14 04:23:47 +03:00
Fix memory leak in libvirt_virStreamRecv.
The libvirt_virStreamRecv function uses a temporary allocated buffer to receive data before copying the data into a Python byte array. But there are some error paths where this buffer is not freed. This change fixes that memory leak. Signed-off-by: Chris Gunn <chrisgun@microsoft.com>
This commit is contained in:
@@ -7926,10 +7926,14 @@ libvirt_virStreamRecv(PyObject *self ATTRIBUTE_UNUSED,
|
|||||||
buf[ret > -1 ? ret : 0] = '\0';
|
buf[ret > -1 ? ret : 0] = '\0';
|
||||||
DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
|
DEBUG("StreamRecv ret=%d strlen=%d\n", ret, (int) strlen(buf));
|
||||||
|
|
||||||
if (ret == -2)
|
if (ret == -2) {
|
||||||
|
VIR_FREE(buf);
|
||||||
return libvirt_intWrap(ret);
|
return libvirt_intWrap(ret);
|
||||||
if (ret < 0)
|
}
|
||||||
|
if (ret < 0) {
|
||||||
|
VIR_FREE(buf);
|
||||||
return VIR_PY_NONE;
|
return VIR_PY_NONE;
|
||||||
|
}
|
||||||
rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
|
rv = libvirt_charPtrSizeWrap((char *) buf, (Py_ssize_t) ret);
|
||||||
VIR_FREE(buf);
|
VIR_FREE(buf);
|
||||||
return rv;
|
return rv;
|
||||||
|
|||||||
Reference in New Issue
Block a user